dependency-injection

Inject a stateless EJB with @Inject into CDI Weld ManagedBean (JSF 1.2 EJB Application on jboss 6 AS)

↘锁芯ラ 提交于 2019-12-29 04:51:12
问题 Currently I am trying to inject a stateless EJB into a CDI managed controller on Jboss 6 AS Final. The controller is managed in the context an accessible from the JSF pages. If I inject the stateless bean with @EJB it is working. If I inject the stateless EJB with @Inject I get the following Exception: My controller: @Named("TestController") public class TestController { @Inject private TestManagerLocal myTestManager; ... } } My stateless bean: @SuppressWarnings("unchecked") @Stateless public

How to dynamically inject a service using a runtime “qualifier” variable?

£可爱£侵袭症+ 提交于 2019-12-29 03:37:05
问题 I can't find a simple way to inject a component/service given a runtime value. I started reading @ Spring's doc: http://docs.spring.io/spring/docs/current/spring-framework-reference/html/beans.html#beans-autowired-annotation-qualifiers but I can't find there how to variabilize the values passed to the @Qualifier annotation. Let's say I've got a model entity with such interface: public interface Case { String getCountryCode(); void setCountryCode(String countryCode); } In my client code, I

Understanding the necessity of type Safety in CDI

旧城冷巷雨未停 提交于 2019-12-29 03:34:06
问题 First I should clarify that this post is not intended to criticize CDI, but to discover the thinking and assumptions behind the design of CDI and that will have obvious influence on designing any web app, which uses CDI. One of the most distinguished feature of CDI (of Java EE 6) is type safety . Jboss Seam was not safe in type. It uses name to qualify any instance to inject. Like bellow: @Name("myBean") public class MyBean implements Bean { ... } @Name("yourBean") public class YourBean

Angular DI and inheritance: injecting extensions of a base service

安稳与你 提交于 2019-12-29 01:52:10
问题 I have a base service and two inhering services: @Injectable({ providedIn: 'root' }) export class BaseService { foo(src?: string){ return `speaking from ${src || 'BaseService'}`; } } @Injectable({ providedIn: 'root' }) export class SomeService extends BaseService { foo(){ return super.foo('SomeService') } } @Injectable({ providedIn: 'root' }) export class AnotherService extends BaseService { foo(){ return super.foo('AnotherService') } } I wish to inject them in some component and retrieve

How to configure Ninject so that it creates a single instance per Controller

走远了吗. 提交于 2019-12-29 01:44:09
问题 I'm trying to use Ninject for an MVC5 application and I want to know if there's any way I can configure it so that instantiate a single object per Controller (I'm not sure if it the same as per request), use that instance in any Action of the controller and once the Action has finished release all the resources that the object utilized. The class that I want Ninject to inject in my controllers implements the IDisposable interface. So far I have tried this: private static void RegisterServices

Angular 2 Injectable Interface?

房东的猫 提交于 2019-12-29 01:42:11
问题 Today I stumbled upon something that I didn't think would cause me trouble. In Java and Spring, I can declare two beans that both implement a given interface, while in another class where they are injected I only work with the interface; this is in fact what I love with IoC: you don't really have to know what object you're working with, only it's kind . So in my little Angular2/Typescript program, I was trying to do the same: webapp.module.ts: ... import { WebAppConfigurationService } from '.

custom Guice binding annotations with parameters

旧街凉风 提交于 2019-12-28 23:20:43
问题 I have successfully created a Guice binding annotation to inject single threaded java.util.concurrent.ExecutorService instances into a constructor. here is an example usage: public class ContainsSingleThreadedExecutorService { private final ExecutorService executorService; @Inject public ContainsSingleThreadedExecutorService(@SingleThreaded ExecutorService executorService) { this.executorService = executorService; } } I now want to create a similar annotation for multi-threaded executors,

How do you configure the DbContext when creating Migrations in Entity Framework Core?

ぐ巨炮叔叔 提交于 2019-12-28 22:29:52
问题 Is there way that dependency injection can be configured/bootstrapped when using Entity Framework's migration commands? Entity Framework Core supports dependency injection for DbContext subclasses. This mechanism includes allowing for configuration of data access outside of of the DbContext . For example, the following would configure EF to persist to a SQL server using a connection string retrieved from config.json ServiceCollection services = ... var configuration = new Configuration()

How do you configure the DbContext when creating Migrations in Entity Framework Core?

自作多情 提交于 2019-12-28 22:29:27
问题 Is there way that dependency injection can be configured/bootstrapped when using Entity Framework's migration commands? Entity Framework Core supports dependency injection for DbContext subclasses. This mechanism includes allowing for configuration of data access outside of of the DbContext . For example, the following would configure EF to persist to a SQL server using a connection string retrieved from config.json ServiceCollection services = ... var configuration = new Configuration()

Dependency injection with unique_ptr to mock

霸气de小男生 提交于 2019-12-28 17:55:37
问题 I have a class Foo that uses class Bar. Bar is used only in Foo and Foo is managing Bar, therefore I use unique_ptr (not a reference, because I don't need Bar outside of Foo): using namespace std; struct IBar { virtual ~IBar() = default; virtual void DoSth() = 0; }; struct Bar : public IBar { void DoSth() override { cout <<"Bar is doing sth" << endl;}; }; struct Foo { Foo(unique_ptr<IBar> bar) : bar_(std::move(bar)) {} void DoIt() { bar_->DoSth(); } private: unique_ptr<IBar> bar_; }; So far