JasperFx / lamar

Fast Inversion of Control Tool and Successor to StructureMap
https://jasperfx.github.io/lamar
MIT License
568 stars 119 forks source link

How wan we Inject dependency while registering ServiceRegistry #162

Closed coredevsushant closed 5 years ago

coredevsushant commented 5 years ago

I wanted to call one static class in which I need to pass IConfiguration, which will get called on startup

static class stay in Infrastructure layer I don't want to add a reference in the main application

Startup.cs public void ConfigureContainer(ServiceRegistry services) { services.AddMvc().SetCompatibilityVersion(CompatibilityVersion.Version_2_2); services.Scan(scan => { scan.TheCallingAssembly(); scan.WithDefaultConventions(); scan.SingleImplementationsOfInterface(); scan.LookForRegistries(); }); }

I don't want to add a reference to Infrastructure Layer into the main calling application (in this case its Web Application)

I need to pass IConfiguration object SomeRegistry class which stay in the Infrastructure Layer In the following code, I am always getting configuration as null

SomeStaticRepository.Initialize is a static class in which I am assigning values and in my requirement, I am going to call directly a static class.

SomeRegistry.cs public class SomeRegistry: ServiceRegistry { public SomeRegistry() { //.......Repo Layers DI registration Container container = new Container(this); IConfiguration configuration = container.TryGetInstance(); // I am always getting "null" SomeStaticRepository.Initialize(configuration); } }

jeremydmiller commented 5 years ago

You might just wanna read over the docs a little better. You can either pass the exact IConfiguration object into your ServiceRegistry, or assume that something else registers it and use it in any kind of Lambda registration