How do I handle classes with static methods with Ninject?

If you’re building a singleton or something of that nature and trying to inject dependencies, typically you instead write your code as a normal class, without trying to put in lots of (probably incorrect) code managing the singleton and instead register the object InSingletonScope (v2 – you didnt mention your Ninject version). Each time you … Read more

Resolving HttpControllerContext with Castle Windsor

Just for the sake of completeness, an answer I got from Krzysztof Koźmic (the current maintainer of Castle Windsor) on Twitter indicated that the method outlined in the question is, indeed, the correct way of achieving this particular goal. (However, I can’t link to that tweet, since Krzysztof’s twitter account is protected (tweets are not … Read more

Net Core Dependency Injection for Non-Controller

You can easily define a static class with one property like: public static class StaticServiceProvider { public static IServiceProvider Provider { get; set; } } after defined class you have to scope the service in the Startup.ConfigureServices method: public void ConfigureServices(IServiceCollection services) { //TODO: … services.AddScoped<IUnitOfWork, HttpUnitOfWork>(); services.AddSingleton<ISomeInterface, ISomeImplementation>(); } then inside the Startup.Configure method … Read more

Passing constructor arguments when using StructureMap

I suggest declaring that with the StructureMap configuration. Using the slightly newer StructureMap code: For<IProductProvider>().Use<ProductProvider> .Ctor<string>(“connectionString”).Is(someValueAtRunTime); This way you don’t burden your client code from having to know the value and can keep your IoC configuration separate from your main code.

ASP.Net Core Call a controller from another controller

How can I use the dependency injection system builtin to ASP.Net 5 to create an instance of the required API controller for me? In your Startup.cs can tell the MVC to register all your controllers as services. services.AddMvc().AddControllersAsServices(); Then you can simply inject the desired controller in your other controller via the DI mechanism and … Read more

MEF (Managed Extensibility Framework) vs IoC/DI

The principle purpose of MEF is extensibility; to serve as a ‘plug-in’ framework for when the author of the application and the author of the plug-in (extension) are different and have no particular knowledge of each other beyond a published interface (contract) library. Another problem space MEF addresses that’s different from the usual IoC suspects, … Read more

What is the purpose of the getter methods in Components in Dagger 2?

Usage in dependent components In the context of a hierarchy of dependent components, such as in this example, provision methods such as Foo foo() are for exposing bindings to a dependent component. “Expose” means “make available” or even “publish”. Note that the name of the method itself is actually irrelevant. Some programmers choose to name … Read more