dependency-injection

Get All Types That Implement An Interface In Unity

亡梦爱人 提交于 2019-12-12 08:55:32
问题 Please skip to the UPDATE if you would like to just know the solution: I have an application that uses the following code to get and run a number of worker methods var type = typeof(IJob); var types = AppDomain.CurrentDomain.GetAssemblies() .SelectMany(x => x.GetTypes()) .Where(x => x.IsClass && type.IsAssignableFrom(x)); foreach (Type t in types) { IJob obj = Activator.CreateInstance(t) as IJob; obj.Run(); } This code works perfectly as is. However, some of the newer jobs utilize dependency

Dependency injection in factories

六月ゝ 毕业季﹏ 提交于 2019-12-12 08:54:23
问题 I'm really new to DI, but I really want to try using it. There's something I don't understand. Here's a simple pseudocode of a factory, I'm using a lot. class PageFactory { public function __construct(/* dependency list */) { ... //save reference to the dependencies } public function createPage($pagename) { switch ($pagename) { case HomePage::name: return new HomePage(/* dependency list */); case ContactPage::name: return new ContactPage(/* dependency list */); ... default: return null; } } }

Injecting EJB into servlet

六眼飞鱼酱① 提交于 2019-12-12 08:49:49
问题 I googled without luck trying to understand why Weblogic 10.3.4 does not inject EJB into annoted field in servlet. Ear contains ejb.jar defining DAO EJB and web.war with TestServlet. PluginDataDAO.java @Stateless public class PluginDataDAO implements IPluginDataDAO { } IPluginDataDAO.java @Local public interface IPluginDataDAO { } TestServlet.java public class TestServlet extends HttpServlet { @EJB(mappedName = "PluginDataDAO") private IPluginDataDAO pluginDataDAO; } web.xml <web-app version=

Custom ActionInvoker vs custom FilterProvider for ActionFilter dependency injection in MVC 3

时光总嘲笑我的痴心妄想 提交于 2019-12-12 08:39:40
问题 Can anyone shed some light on the advantages and disadvantages of using a custom ActionInvoker like so to perform dependency injection on custom ActionFilters as opposed to using a custom FilterProvider as demonstrated here? In both cases you are going to still want to avoid constructor injection on your ActionFilters, and to me it seems that all the custom FilterProvider does in this case is adds additional overhead of having to register your ActionFilters and the provider in your container.

Dependency injection with Akka

巧了我就是萌 提交于 2019-12-12 08:36:23
问题 I use Guice in my application quite a lot. Recently i start to learn akka actors and felt like refactoring my application with it. However upfront i am already wondering how all my guice will work with actors. I went on searching on google and it is kinda a bit messy. The most up to date docs that i have found on the subject are theses: http://letitcrash.com/post/55958814293/akka-dependency-injection http://eng.42go.com/tag/guice/ which do not advocate same thing. I must confess i still need

Using CDI without a Servlet Container

落花浮王杯 提交于 2019-12-12 08:29:27
问题 I want to write a simple Java Desktop Application using Java Swing. Usually I use Spring Framework to do the dependency injection and build the whole class structure. However, I've seen that CDI is becoming more and more popular and want to give it a try. I would like to do the Dependency Injection of my project using CDI, but I don't know if this is possible without a Servlet container (as it is using Spring). Every single tutorial seems to be related with servlet containers or application

A .NET Unit Test without a parameterless constructor, to facilitate dependency injection

末鹿安然 提交于 2019-12-12 08:23:08
问题 I'm trying to have the unit tests not rely on calling container.Resolve<T>() for their dependencies. I'm currently using AutoFac 2.2.4, and tried xUnit.NET and NUnit , but both have this issue : No parameterless constructor defined for this object How do I get past this issue? Is it a particular unit testing framework that will support this, or just how said framework is configured? Should I not be doing this? Or can I set up the test class to work with the constructor that has it's only

Spring - is using new a bad practice?

匆匆过客 提交于 2019-12-12 08:12:51
问题 Is creating objects by hand , i.e. using new operator instead of registering Spring bean and using dependency injection considered bad practice? I mean, does Spring IoC container have to know about all objects in the application? If so, why? 回答1: You want Spring to create beans for classes that : you want/need to inject instance(s) in other beans you need to inject beans (or dependencies) in their own instances. you want them to benefit from Spring features (instantiation management,

Is it possible to register all classes within a package as Spring beans

我的未来我决定 提交于 2019-12-12 08:09:38
问题 I'm familiar with Springs Java based configuration options, including the usage of @Component and @Configuration in conjunction with @Bean annotations to register Spring beans. However, when converting a decent size project to Spring, it can be very labor intensive to systematically touch all classes in the project and update with @Configuration @Bean s or annotating each class with @Component . We have a large Groovy project to be converted and I would like to simplify the process. My

Can you only inject services into services through bootstrap?

南楼画角 提交于 2019-12-12 08:01:37
问题 I am trying to wire up a basic Angular2 app that uses the Http service. (Most of the tutorials I've seen do this by having a Component consume the Http service, which seems wrong unless the basic philosophy of thin controllers has changed – but that's a different question.) I would like to create a service that uses Angular's Http service. But I can't figure out how to inject the Http service other than this: boot.ts: import {bootstrap} from 'angular2/platform/browser'; import {AppComponent}