What is the difference between Strategy pattern and Dependency Injection?

DI and Strategy work in the same way, but Strategy is used for more fine-grained and short-lived dependencies. When an object is configured with a “fixed” Strategy, for example when the object is constructed, the distinction between Strategy and DI blurs. But in a DI scenario it is more unusual that the dependencies of objects … Read more

How to inject Injector?

You should not be using the Injector directly. Rather pass in the Provider<FooClass> instead. Also, you should be injecting the provider in the places where you use FooClass. private final Provider<FooClass> provider; @Inject public ClassWhereFooIsUsed(Provider<FooClass> provider) { this.provider = provider; } …. somewhere else FooClass f = provider.get(); // This is lazy

Simple Dependency Resolver

DI Containers are complex libraries. Building them takes years and maintaining them decades. But to demonstrate their working, you can write a simplistic implementations in just a few lines of code. At its core a DI Container would typically wrap a dictionary with System.Type as its key and, the value would be some object that … Read more

Dependency Injection – new instance required in several of a classes methods

Most of the answers here so far suggest that you change the injected dependency type to some sort of Abstract Factory (a Func<T> is also an Abstract Factory) to address the issue. However, if you do that it would be a leaky abstraction because you would let the knowledge of a particular implementation determine the … Read more

Autofac and Func factories

You are calling secVMFactory outside of your FirstViewModel constructor so by that time the ResolveOperation is disposed and in your factory method the c.Resolve will throw the exception. Luckily the exception message is very descriptive and telling you what to do: When registering components using lambdas, the IComponentContext ‘c’ parameter to the lambda cannot be … Read more

Angular 2: Inject service into class

I’ve managed to resolve my problem. Angular 2 – 4 provides reflective injector that allows to inject dependencies outside of constructor parameters. All I had to do was to import Reflective injector from @angular/core. import {ReflectiveInjector} from ‘@angular/core’; And then: let injector = ReflectiveInjector.resolveAndCreate([DrawingService]); this.drawingApi = injector.get(DrawingService); The class doesn’t even have to be decorated … Read more

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)