Base solution for your next web application
Open Closed

How to register dependency implementation #3869


User avatar
0
strix20 created

I'm in the process of upgrading my project to v4.5 to migrate to core 2.0. It seems the 4.5 project has startup has not been modified to adhere to the new .net core 2.0 configuration setup. All configuration should be moved to program.cs, and startup should inject a dependency of IConfiguration.

(see [https://joonasw.net/view/aspnet-core-2-configuration-changes]))

I have made these changes myself, and I noticed that there are several places where ABP / Zero erroneously uses IConfigurationRoot instead of the proper IConfiguration. I have changed those as well in my project, and the MVC project works fine.

However, the Migration project fails to run, because it cannot resolve the IConfiguration dependency properly. I have tried to work out how to register this dependency manually, but it appears that the IOCManager provided by ABP, which wraps Castle Windsor, does not provide a way to register a singleton.

How can this be done?


2 Answer(s)
  • User Avatar
    0
    hikalkan created
    Support Team

    Hi,

    You can register your dependencies inside this method: <a class="postlink" href="https://github.com/aspnetzero/aspnet-zero-core/blob/dev/aspnet-core/src/MyCompanyName.AbpZeroTemplate.Migrator/AbpZeroTemplateMigratorModule.cs#L41">https://github.com/aspnetzero/aspnet-ze ... ule.cs#L41</a>

    See <a class="postlink" href="https://aspnetboilerplate.com/Pages/Documents/Dependency-Injection#using-iocmanager">https://aspnetboilerplate.com/Pages/Doc ... iocmanager</a> for registering dependencies.

  • User Avatar
    1
    strix20 created

    I looked at that, but the ABP framework does not expose a way to register an instance directly.

    I managed to get it working by doing the following:

    var config = AppConfigurations.Get(typeof(CustomsMigratorModule).GetAssembly().GetDirectoryPathOrNull());
    
                    bootstrapper.IocManager.IocContainer.Register(Component.For<IConfiguration>().Instance(config));
    

    But that seems really messy. Is there a reason that IocManager does now have a way to register an instance built into it?