dependency-injection

Java EE 7 - Injection into Runnable/Callable object

非 Y 不嫁゛ 提交于 2020-01-02 01:25:28
问题 Concurrency Utilities(JSR 236) has been introduced in Java EE 7. Is there any way how to inject my EJBs into Runnable/Callable object? Specifically I want something like this: ejb with business logic @LocalBean public class MyEjb { public void doSomeStuff() { ... do some stuff ... } } runnable/callable class where I want to inject instance of MyEjb public class MyTask implements Runnable { @EJB MyEjb myEjb; @Override public void run() { ... myEjb.doSomeStuff(); ... } } Object which starts the

Registering implementations of base class with Autofac to pass in via IEnumerable

放肆的年华 提交于 2020-01-02 01:10:19
问题 I have a base class, and a series of other classes inheriting from this: (Please excuse the over-used animal analogy) public abstract class Animal { } public class Dog : Animal { } public class Cat : Animal { } I then have a class that has a dependancy on an IEnumerable<Animal> public class AnimalFeeder { private readonly IEnumerable<Animal> _animals; public AnimalFeeder(IEnumerable<Animal> animals ) { _animals = animals; } } If I manually do something like this: var animals = typeof(Animal)

When to use interfaces, and when to use higher order functions?

我是研究僧i 提交于 2020-01-02 00:59:09
问题 Given a ASP.NET MVC application with the following layers: UI (Views, CSS, Javascript, etc.) Controllers Services (Contains business logic, and data access) The reason for no separate data access layer, is that I'm using SQL type provider. (The following code may not be working, as it's only a raw draft). Now imagine a service named UserService defined like: module UserService = let getAll memoize f = memoize(fun _ -> f) let tryGetByID id f memoize = memoize(fun _ -> f id) let add evict f

Assembly added via Add Reference not copied to output directory unless referred to in code

偶尔善良 提交于 2020-01-02 00:55:09
问题 Situation: Project 1 is an assembly in the solution Project 2 is an executable assembly project in the same solution Project 2 has a project reference (via Add Reference) to Project 1 Project 2 does not directly refer to namespaces/types in Project 1 in the code Project 2 uses Ninject to dynamically load Project 1 and use the implementation classes within it Problem: Even though Copy Local is set to True for the reference, and the referenced assembly does not exist in the GAC, the referenced

What is the equivalent of HybridHttpOrThreadLocalScoped in structure map 3?

天涯浪子 提交于 2020-01-02 00:54:10
问题 With structuremap 2.6.4.1 my container is configured like this: existingContainer.Configure(expression => { expression.For<IDocumentSession>() .HybridHttpOrThreadLocalScoped() .Use(container => { var store = container.GetInstance<IDocumentStore>(); return store.OpenSession(); }); } HybridHttpOrThreadLocalScoped does not exist in structure map 3 so my question is, what is the equivalent configuration in structuremap 3? 回答1: As of StructureMap 3, anything HttpContext related lives within a

Repository pattern with generics and DI

馋奶兔 提交于 2020-01-01 19:50:50
问题 I have a base repository contract which other contracts extend, like follows public interface IBaseRepository<T> where T : class { IList<T> GetContents(); } and then there are other contracts which extend it like follows public interface IRepository1 : IBaseRepository<MyClass1> { } public interface IRepository2 : IBaseRepository<MyClass2> { } I implement IRepository1 as follows public class Repository1 : IRepository1 { public IList<MyClass1> GetContents() { //some code goes here } } similarly

spring ioc injecting concrete implementation of interface to test

风格不统一 提交于 2020-01-01 19:40:54
问题 I have the following setup: @Component public class ImplOne implements IFace{ } @Component public class ImplTwo implements IFace{ } public interface IFace{ } I am trying to get a reference of ImplOne by type: @RunWith(SpringJUnit4ClassRunner.class) public class ImplOneTest { @Autowired private ImplOne impl; @Test public void test(){ Assert.assertNotNull(impl); } } Though with this I get the following exception: org.springframework.beans.factory.NoSuchBeanDefinitionException: No matching bean

Guice log4j custom injection does not support logging within the constructor

点点圈 提交于 2020-01-01 17:26:37
问题 I'm trying to use Guice to inject Log4J Logger instances into classes as described in the Guice documentation: http://code.google.com/p/google-guice/wiki/CustomInjections However, as noted in some of the comments on that wiki page, this scheme does not support a constructor injection. So I can't do this: public class Foo { @InjectLogger Logger logger; @Inject public Foo(<injected parameters>) { logger.info("this won't work because logger hasn't been injected yet"); ... } public bar() { logger

Guice log4j custom injection does not support logging within the constructor

你离开我真会死。 提交于 2020-01-01 17:26:13
问题 I'm trying to use Guice to inject Log4J Logger instances into classes as described in the Guice documentation: http://code.google.com/p/google-guice/wiki/CustomInjections However, as noted in some of the comments on that wiki page, this scheme does not support a constructor injection. So I can't do this: public class Foo { @InjectLogger Logger logger; @Inject public Foo(<injected parameters>) { logger.info("this won't work because logger hasn't been injected yet"); ... } public bar() { logger

Using Ninject 2.0 with ASP .Net 3.5

天涯浪子 提交于 2020-01-01 16:49:44
问题 I am trying to use Ninject 2.0 with Asp .Net 3.5 web application. Following are the DLLS and it's versions I am using. Ninject.dll - v2.0.0.0 Ninject.Extensions.Logging.dll v2.0.0.0 Ninject.Web.dll v1.0.0.0 In my global.ascx.cs I have following method. protected override IKernel CreateKernel() { IKernel kernel = new StandardKernel(); kernel.Bind<IDataAccess>().To<DataAccessEntBlock>().InSingletonScope(); return kernel; } When I run the application I get following error. Error activating