How to inject a repository into a service in Symfony?

Here is a cleaned up solution for those coming from Google like me: Update: here is the Symfony 2.6 (and up) solution: services: myrepository: class: Doctrine\ORM\EntityRepository factory: [“@doctrine.orm.entity_manager”, getRepository] arguments: – MyBundle\Entity\MyClass myservice: class: MyBundle\Service\MyService arguments: – “@myrepository” Deprecated solution (Symfony 2.5 and less): services: myrepository: class: Doctrine\ORM\EntityRepository factory_service: doctrine.orm.entity_manager factory_method: getRepository arguments: – MyBundle\Entity\MyClass … Read more

Replace service registration in ASP.NET Core built-in DI container?

This is simple using the Replace(IServiceCollection, ServiceDescriptor) method from the ServiceCollectionDescriptorExtensions class. // IFoo -> FooA services.AddTransient<IFoo, FooA>(); // Replace // IFoo -> FooB var descriptor = new ServiceDescriptor( typeof(IFoo), typeof(FooB), ServiceLifetime.Transient); services.Replace(descriptor); See also: ServiceDescriptor constructors

HK2 is not injecting the HttpServletRequest with jersey

You should @Override protected DeploymentContext configureDeployment() in the JerseyTest to return a ServletDeploymentContext. For example import javax.inject.Inject; import javax.inject.Provider; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpSession; import javax.ws.rs.GET; import javax.ws.rs.Path; import javax.ws.rs.core.Response; import org.glassfish.hk2.api.Factory; import org.glassfish.hk2.utilities.binding.AbstractBinder; import org.glassfish.jersey.server.ResourceConfig; import org.glassfish.jersey.servlet.ServletContainer; import org.glassfish.jersey.test.DeploymentContext; import org.glassfish.jersey.test.JerseyTest; import org.glassfish.jersey.test.ServletDeploymentContext; import org.glassfish.jersey.test.grizzly.GrizzlyWebTestContainerFactory; import org.glassfish.jersey.test.spi.TestContainerException; import org.glassfish.jersey.test.spi.TestContainerFactory; import org.junit.Test; public class ServletTest extends … Read more

Create new instance of class that has dependencies, not understanding factory provider

You can provide a factory function. This is different from a simple useFactory: … provider like { provide: ‘TestModelFactory’, useFactory: () => { return (http, config) => { return new TestModel(http, config); }; }, deps: [Http, CONFIG]; } and then use it like @Injectable() export class TestService { constructor(@Inject(‘TestModelFactory’ testModelFactory) {} getTestsModels(): Observable<TestModel[]> { let … Read more

Dependency Injection wcf

When you use svcutil.exe or the Add Service Reference wizard in Visual Studio, one of the many types auto-generated will be a client interface. Let’s call it IMyService. There will also be another auto-generated interface called something like IMyServiceChannel that implements IMyService and IDisposable. Use this abstraction in the rest of your client application. Since … Read more

Cake pattern with overriding abstract type don’t work with Upper Type Bounds

It’s a shortcoming of Scala’s type system. When determining the members in a mixin, Scala uses two rules: First, concrete always overrides abstract. Second, If two members are both concrete, or both abstract, then the one that comes later in linearization order wins. Furthermore, the self type of a trait trait S { this: C … Read more

Autowiring in Spring bean (@Component) created with new keyword

Yours component “A” is not created by Spring container, thus, dependencies are not injected. However, if you need to support some legacy code (as I understand from your question), you can use @Configurable annotation and build/compile time weaving: @Configurable(autowire = Autowire.BY_TYPE) public class A extends TimerTask { // (…) } Then, Spring will inject autowired … Read more