dependency-injection

Ninject: GetAll instances that inherit from the same abstract class

☆樱花仙子☆ 提交于 2019-12-14 03:20:34
问题 Is it possible for Ninject to get all instances that inherit from a specific Abstract Class? For example, I have the following Abstract Class. public abstract class MyAbstractClass { } Then I have the following two derived classes that both inherit from the same abstract class. public class MyDerivedClass1 : MyAbstractClass { } public class MyDerivedClass2 : MyAbstractClass { } Now I am going to bind both derived classes with the Kernel because I want them to be in singleton scope. _kernel =

ASP.NET MVC4 NServiceBus Attribute/Filter StructureMap

我只是一个虾纸丫 提交于 2019-12-14 03:12:08
问题 I'm having issues getting an instance of IBus in an action filter (attribute). From Setting IBus Property in MVC Filter, I know that DI and action filters don't play nice, and I got them play nice using the accepted answer. The problem is that getting DI and action filters to play nice breaks NServiceBus. That same question had a suggestion by John to look at the video store solution to see how to get it done. There are two problems with that answer: It totally ignores the fact that I'm using

Dependency Inject with Ninject 2.0

天涯浪子 提交于 2019-12-14 02:47:43
问题 A little question regarding Ninject. I use a WCF 'duplex channel' to communicate with a service. The channel is defined as an interface, lets call it IMyChannel for simplicity. To instantiate a channel we use DuplexChannelFactory<IMyChannel> object's CreateChannel() method. So far I have manage to bind the factory class with this. Bind< DuplexChannelFactory< IMyChannel>>().ToMethod(context => new DuplexChannelFactory< IMyChannel>( new MessageEndPoint(), new NetTcpBinding(), "net.tcp:/

symfony DIC 3.0 prototype services

雨燕双飞 提交于 2019-12-14 02:38:46
问题 Prototype service means service, which is passed as dependency as always new fresh instance. In the end its similar to cloning the dependency in instance where its required, but its clean solution. As writen on Symfony news Twitter, scopes was officially deprecated. prototype services was set up by scopes. How can i set prototype services in Symfony DIC 3.0 configuration? (I prefer yml) 回答1: From looking at the upgrade 2.7 to 2.8 it says that the scope: prototype flag has been changed to

Android using Dependency Injection on Fragments

ε祈祈猫儿з 提交于 2019-12-14 02:29:45
问题 I can use Dependency Injection for Realm successful, i can use @Inject into activity without any problem, now i want to use that and inject that into Fragments, since i novice to use this method, i can't do that ApplicationModule class: @Module public class ApplicationModule { @Provides Context provideApplicationContext() { return AlachiqApplication.getInstance(); } @Provides @Singleton RealmConfiguration provideRealmConfiguration() { final RealmConfiguration.Builder builder = new

How do I inject mocks into a Spring class marked as “@Transactional”?

自作多情 提交于 2019-12-14 02:23:48
问题 I'm using SPring 3.1.1.RELEASE and JUnit 4.8.1. In my test class, I want to mock a private field and discovered the beauty of "ReflectionTestUtils" ... @RunWith(SpringJUnit4ClassRunner.class) @ContextConfiguration({ "classpath:test-context.xml" }) public class OrderServiceTest extends AbstractTransactionalJUnit4SpringContextTests … @Autowired private OrderService m_orderSvc; @Test public void testGetPDOrders() throws QuickBaseException, Exception { … ReflectionTestUtils.setField(m_orderSvc,

Do DI Containers need to instantiate the object themselves in order to use constructor injection?

梦想与她 提交于 2019-12-14 02:18:08
问题 Or instead of creating the object themselves, do they somehow intercept or hook into object creation (for example, a Controller instantiated by the MVC framework) and pass in whatever dependencies they're required to? I realize they need to do something when the object is created in order to use constructor injection, but I am unclear as to whether the containers need to do the creating, or if they somehow intercept the object's creation. Whatever the answer is, do all DI containers do it

How to set a bean qualifier name at run time in Spring

感情迁移 提交于 2019-12-14 01:43:38
问题 We can set qualifier names for a bean (for example @Qualifier(value="myBeanQualifiedName") ) . but I want to know how to set a Qualifier name at run time in a @Configuration class. Assume based on a application logic I want to give a name to a bean as a qualifier in a configuration file. EDITED: ConcreteBean is a child class of MyAbstractBean. @Configuration public class MyBeanFactory { @Bean public MyAbstractBean getMySpecifiedBean(String condition){ String QUALIFIER_NAME="QulifierName"

EJB dependency injection of remote service fails on Glassfish

£可爱£侵袭症+ 提交于 2019-12-14 01:27:12
问题 I am unable to get dependency injection to work for my remote service and I cannot figure out why. I want an instance of RemoteService so I wrote. @EJB(name="RemoteService") private RemoteService service; And the Bean itself is defined with mappedName="RemoteService: @Stateless(mappedName = "RemoteService") public class RemoteServiceBean implements RemoteService When I try to run this code I get an InjectionException: EJB5070: Exception creating stateless session bean : [{0}] com.sun

Extending ActionDescriptorFilterProvider to allow dependency injection of class level filters

眉间皱痕 提交于 2019-12-14 01:06:31
问题 Following up on Authorization Filter Dependency Injection with ASP.New MVC 4 Web Api . Is there a way to use dependency injection on filters that are set globally on all controller classes: config.Filters.Add(new WebApplicationApiAuthorizeAttribute()); It looks like the GetFilters method in the ActionDescriptorFilterProvider only works on method level filters. public class UnityWebApiFilterAttributeFilterProvider : ActionDescriptorFilterProvider, System.Web.Http.Filters.IFilterProvider {