dependency-injection

Spring: Why do we autowire the interface and not the implemented class?

限于喜欢 提交于 2019-12-27 11:11:11
问题 Example interface IA { public void someFunction(); } @Resource(name="b") class B implements IA { public void someFunction() { //busy code block } public void someBfunc() { //doing b things } } @Resource(name="c") class C implements IA { public void someFunction() { //busy code block } public void someCfunc() { //doing C things } } class MyRunner { @Autowire @Qualifier("b") IA worker; worker.someFunction(); } Can someone explain this to me. How does spring know which polymorphic type to use.

How to inject an object into jersey request context?

喜你入骨 提交于 2019-12-27 11:06:54
问题 I have this scenario where I want to write a filter and I want this filter to insert some object into the current request and pass it on so that when the resource class gets the request it can use the object. Filter class @Override public void filter(ContainerRequestContext request) throws IOException { MyObject obj = new MyObject(); // Inject MyObject to request which I dont know how } Resource Class @PUT @Consumes("application/json") @Path("/") public String create( JSONParam sample,

How to inject an object into jersey request context?

老子叫甜甜 提交于 2019-12-27 11:05:48
问题 I have this scenario where I want to write a filter and I want this filter to insert some object into the current request and pass it on so that when the resource class gets the request it can use the object. Filter class @Override public void filter(ContainerRequestContext request) throws IOException { MyObject obj = new MyObject(); // Inject MyObject to request which I dont know how } Resource Class @PUT @Consumes("application/json") @Path("/") public String create( JSONParam sample,

Not able to understand dagger dependency injection concepts - Dagger 2 on android [closed]

人走茶凉 提交于 2019-12-25 21:01:09
问题 Closed . This question needs to be more focused. It is not currently accepting answers. Want to improve this question? Update the question so it focuses on one problem only by editing this post. Closed 2 years ago . I am trying to understand dagger2 and implement in my app. I have read a lot about its benefits. Unless and until I understand it completely, I cannot get the benefits of it in my app. I have understood @Module and @Inject. The one that confuses me is @Component. I have few

How to create a class without constructor parameter which has dependency injection

♀尐吖头ヾ 提交于 2019-12-25 18:34:40
问题 I have added the dependency injections to the project. But when i create an instance by using new keyword, dependency injection doesn't work. public class MyClass { ILoginTokenKeyApi _loginTokenKeyApi; public MyClass(ILoginTokenKeyApi loginTokenKeyApi) { _loginTokenKeyApi = loginTokenKeyApi; } ... } When i try to create an instance of MyClass, it wants a parameter to be constructed naturally. Just like this : MyClass mc = new MyClass(); // ERROR, it wants a parameter (but it is what i want) I

Providing/Injecting third party service to component while angular component unit testing

拜拜、爱过 提交于 2019-12-25 17:04:37
问题 I have just started with Angular Unit testing, LoginComponent is dependent on third party module's (Fuse) service FuseConfigService . Here is how FuseConfigService look like @Injectable({ providedIn: 'root' }) export class FuseConfigService { private _configSubject: BehaviorSubject<any>; private readonly _defaultConfig: any; /** * Constructor * * @param {Platform} _platform * @param {Router} _router * @param _config */ constructor( private _platform: Platform, private _router: Router, @Inject

How can i do this better using Ninject IOC

好久不见. 提交于 2019-12-25 16:54:35
问题 the concept is quite popular but I have not found the answer yet. I have the following class structure public interface IMessage { } public class MessageA : IMessage { } public class MessageB : IMessage { } public interface IMessageHandler<T> where T : IMessage { void Handle(TMessage message); } public interface MessageAHandler : IMessageHandler<MessageA> { } public interface MessageBHandler : IMessageHandler<MessageB> { } public class MessageProcessor { public void Process(IMessage) { if

How to use Singleton class injected by .NET MVC Ninject?

我与影子孤独终老i 提交于 2019-12-25 16:26:25
问题 I have some problem with InSingletonScope(). My interface: public interface ISettingsManager { ApplicationSettings Application { get; } } and my class: public class SettingsManager : ISettingsManager { private readonly IConfigurationService _configurationService; private readonly Lazy<ApplicationSettings> _applicationSettings; public ApplicationSettings Application { get { return _applicationSettings.Value; } } private SettingsManager(IConfigurationService context) { _configurationService =

Angular2 component definition with additional configuration decoration

邮差的信 提交于 2019-12-25 14:46:51
问题 I want to pass a provider right to a component. @NgModule({ declarations:[ SomeComponent.withProviders([provider1,provider2]), AnotherComponent.withProviders([provider1,provider2]) ] }) export class NestedModule{} My question: Can I configure my components while defining them in the module like above? More information: The reason do I need such a thing: I need to define a value provider at module level. The component looks at it's parent component to find say provider1 if it doesn't have one.

A JMS XA connection factory injected using spring jee-jndi lookup behaves differently than @Resource injection on Weblogic 12c

这一生的挚爱 提交于 2019-12-25 14:29:27
问题 I have an MDB application recently ported to Weblogic 12c. I use spring 3.1 to inject datasource and jms resources however have found that delivery of message queues does not succeed (without error), appearing to not participate in the XA transaction although no rollback is evident. I have since created a test app to isolate the issue. This test app contains: session timer bean putting message on testQueue1 MDB1 updating the datasource and moving message from testQueue1 to testQueue2. My