Using Dependency Injection with .NET Core Class Library (.NET Standard)

You don’t have to do anything in your class library. Only the main application has a composition root (earliest point in an application lifecycle you can set up your object graph). This happens in Startup.cs in your ASP.NET Core application. There you also register your dependencies: services.AddScoped<IUserManager,UserManager>(); That’s it. Class libraries don’t have a composition … Read more

Where exactly is the difference between IoC and DI [duplicate]

In common usage, the terms have become somewhat synonymous. The original idea of IoC — Inversion of Control — was very much related to the “Hollywood Principle:” Don’t Call Us, We’ll Call You. In traditional applications, developers would write business code and framework code. The business code would then call the framework code to accomplish … Read more

Avoiding all DI antipatterns for types requiring asynchronous initialization

This is a long answer. There’s a summary at the end. Scroll down to the summary if you’re in a hurry. The problem you have, and the application you’re building, is a-typical. It’s a-typical for two reasons: you need (or rather want) asynchronous start-up initialization, and Your application framework (azure functions) supports asynchronous start-up initialization … Read more

Difference between MEF and IoC containers (like Unity, Autofac, SMap, Ninject, Windsor.Spring.net, etc.)

Eventually what I have concluded about the MEF vs IoC container is as follows: MEF is preferred to be used when one has to deal with unknown types or a plugin based architecture. IoC containers are preferred to be used with known types. Moreover, MEF is an architectural solution for dependency injection Whereas, IoC containers … Read more

Why is MVC4 using the Service Locator Anti-Pattern?

That’s an implementation detail that you shouldn’t care about. The important thing is that now that the Web API uses the DependencyResolver to resolve dependencies for many different facilities, you will be able to use a real dependency injection whenever you want to plug into those facilities. So in your code you will be using … Read more

Abstractions should not depend upon details. Details should depend upon abstractions?

It means that if the details change they should not affect the abstraction. The abstraction is the way clients view an object. Exactly what goes on inside the object is not important. Lets take a car for example, the pedals and steering wheel and gear lever are abstractions of what happens inside the engine. They … 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.