How to extend a component with dependency injection?

If you want to avoid this “boiler plate” code injecting services in child classes just for injection in parent classes’ constructor and then effectively using that services in child classes through inheritance, you could do this: edit: from Angular 5.0.0 ReflectiveInjector has been deprecated in favour of StaticInjector, below is updated code to reflect this … Read more

When are .NET Core dependency injected instances disposed?

The resolved objects have the same life-time/dispose cycle as their container, that’s unless you manually dispose the transient services in code using using statement or .Dispose() method. In ASP.NET Core you get a scoped container that’s instantiated per request and gets disposed at the end of the request. At this time, scoped and transient dependencies … Read more

Comparing Castle Windsor, Unity and StructureMap

See here and here for a pretty thorough technical comparison of several IoC containers, although somewhat outdated by now (they’re from before Windsor 2.0) However, I don’t think there are really any vital features that Windsor offers and other containers don’t. Windsor, StructureMap, Spring.NET have all been around for several years and have been used … Read more

When to use PerThreadLifetimeManager?

The Per Thread Lifetime is a very dangerous lifestyle and in general you should not use it in your application, especially web applications. This lifestyle should be considered dangerous, because it is very hard to predict what the actual lifespan of a thread is. When you create and start a thread using new Thread().Start(), you’ll … 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

Inversion of Control < Dependency Injection [closed]

If you accept Fowler’s definition, Inversion of Control is a much broader term than DI that covers all framework usage where you plug into a framework, but the framework is still in control. For example, in .NET, frameworks such as ASP.NET or Windows Presentation Foundation are ultimately in control, but provide various events and Seams … Read more

Inversion of Control vs Dependency Injection

The Inversion-of-Control (IoC) pattern, is about providing any kind of callback (which “implements” and/or controls reaction), instead of acting ourselves directly (in other words, inversion and/or redirecting control to the external handler/controller). For example, rather than having the application call the implementations provided by a library (also known as toolkit), a framework calls the implementations provided by the application. The Dependency-Injection (DI) pattern is a … Read more