dependency-injection

Symfony 3 - EntityManager dependency injection with multiple db connections

落爺英雄遲暮 提交于 2019-12-12 16:12:32
问题 I have setup a Custom Authenticator using guard and auto wired the service. This is tested and works fine with just MySQL configured. I have now specified a second database connection (oracle), but Symfony will now not allow autowiring in my service configuration, because it does not know which database connection to use when injecting EntityManager in to the custom Authenticator class. Any idea how I can Configure the Dependency Injection to use a specific database connection so I can

Uses of PreserveExistingDefaults?

跟風遠走 提交于 2019-12-12 16:08:19
问题 Why and when should we use PreserveExistingDefaults during autofac registration? I have read it's uses form Autoface docs: http://docs.autofac.org/en/latest/register/registration.html But my question is, when is the case we will register multiple implementation with single interface. Can anybody give some example from real time. 回答1: It can be use when you want to register a new implementation without changing the default one. When you register multiple registration for a single interface,

How do I best implement dependency injection when many similar but distinct classes need many similar but distinct dependencies?

倖福魔咒の 提交于 2019-12-12 16:05:40
问题 I'm developing a Windows application in Visual Studio .NET 4.0 where I'm using the MVP pattern and I'm trying to learn and apply dependency injection principles throughout the application. But I'm having trouble understanding how to best handle a particular situation. And I apologize in advance for the long explanation, but I don't know if I could be specific enough otherwise. The application is a general purpose record-keeping app for many different types of records, some of which are

Change service parameter value dynamically for FOSUserBundle

偶尔善良 提交于 2019-12-12 15:21:55
问题 I asked about using multiple entity manager for FOSUserBundle before, and it turns out that FOSUserBundle has (partially) supported that. All I need to do is to specify the connection / manager I want to use in the model_manager_name parameter, as explained here fos_user: # ........ model_manager_name: account1 Sample app/config/config.yml With this FOSUserBundle will use account1 connection, and use user information in that connection's database. doctrine: dbal: default_connection: default

Inject the same component with different parameters with Guice

徘徊边缘 提交于 2019-12-12 14:57:05
问题 I have a Class which represents a graphical Component. This component displays data from the database. Now I have some kind of dashboard, which has 12 of my Components above. Of course I want to reuse this component! So I thought, I could use a Custom Annotation with parameters and pass the parameters to a provider. I found some hack on Stackoverflow (http://stackoverflow.com/questions/5704918/custom-guice-binding-annot...) but to be honest, I did not find any documentation how to implement

Adding a dependency to an EJB

…衆ロ難τιáo~ 提交于 2019-12-12 14:47:34
问题 I want to add a dependency to an EJB. How do I do this using Spring? The dependent object is a general service object. Based on code below I want to wire myDependency without having to use 'new'. The EJB runs in weblogic. @Stateless(mappedName = "MyBean") public class MyBean implements MyBeanRemote, MyBeanLocal { @EJB(name = "MyOtherBean") private MyOtherBean myOtherBean; private MyDependency myDependency; ... } 回答1: This is well described in the Spring documentation: For EJB 3 Session Beans

Injectable factory with Macwire

筅森魡賤 提交于 2019-12-12 14:30:38
问题 I'm teasing out MacWire for dependency injection. One thing that i found useful with Guice is the assisted inject, to autowire a factory that would help you to create some service that needs run parameters. Is there something similar with Macwire ? 回答1: Injectable factories are supported, but are not really a feature of MacWire, rather in MacWire's spirit, you can "just use Scala". In this case, you can use function types. Following the Guice examples, let's say you want to create a Payment

Adding Dependency Injection to an MVVM application

淺唱寂寞╮ 提交于 2019-12-12 14:29:07
问题 Trying to backfill a WPF application using the MVVM pattern to work with dependency injection. I'm not overly familiar with DI, having worked with it only once before, but I think I understand the principles involved. I need to ensure that the bindings are all registered in one place - the application root. In WPF, this is the OnStartup method. So, I grabbed Ninject and threw it into my application to try and automatically bind my repository class to the initial view: private void OnStartup

How can I inject the Repositories to the UnitOfWork?

橙三吉。 提交于 2019-12-12 14:22:44
问题 I've implemented my UnitOfWork so that it keeps references to all repositories. public interface IUnitOfWork { void Commit(); void RollBack(); } public interface IMyUnitOfWork : IUnitOfWork { IFooRepository Foos { get; } IBarRepository Bars { get; } // Other repositories ... } Note that the repositories implements a generic type of repository interface. public interface IFooRepository : IRepository<Entities.Foo> { // FooRepository specific methods goes here. } public interface IRepository<T>

Spring dependency injection with WildFly

落花浮王杯 提交于 2019-12-12 14:14:28
问题 I have a web application (war file) that depends (Maven) on another project (jar file) that uses Spring for dependency injection. So in that other project I have a couple of xml files to declare my beans, in my case business objects. I started using WildFly instead of Tomcat/Jetty and apparently there is that thing called Weld in charge of DI. My web app doesn't use Spring (for now), it's just a simple Jersey RESTful API. I want my business objects to be injectable (@Inject) in my resources