dependency-injection

Interfaces are annotated with @Component annotation in spring IoC/DI. What could be the reason?

不问归期 提交于 2019-12-20 05:25:35
问题 Some times interfaces are annotated with @Component annotation. Then my obvious reasoning was that classes that implement such interface will be treated as components as well. But if I am right that is not the case. So what is the purpose of @Component annotation on interfaces. 回答1: Annotating an interface with @Component is common for Spring classes, particularly for some Spring stereotype annotations : package org.springframework.stereotype; ... @Component public @interface Service {...} or

Spring @Autowired(required = true) is null [duplicate]

无人久伴 提交于 2019-12-20 05:17:31
问题 This question already has answers here : Spring JSF integration: how to inject a Spring component/service in JSF managed bean? (3 answers) Closed 3 years ago . I have a webmodule with JSF 2 end Spring 4.3. In a backing bean I use @Autowired for DI of a service of a JAR. In EAR module there are WAR, JAR with @Service Spring and JAR with Spring configuration file. Below a web.xml snippet: <context-param> <param-name>locatorFactorySelector</param-name> <param-value>classpath:beanRefContext.xml<

Unable to inject DBContext into my Web API 2 Controller with Unity

浪尽此生 提交于 2019-12-20 04:25:16
问题 I've been at it for days, but I can't get Unity to inject anything with RegisterType<> into my Controller . I'm using Web Api 2, in Visual Studio 2015, with Unity 4. Whenever I try to inject IUnitOfWork or IRFContext , I get "message": "An error occurred when trying to create a controller of type 'ClPlayersController'. Make sure that the controller has a parameterless public constructor." . I'm using the Unity.AspNet.WebApi to bootstrapp into WebApi. Below is my UnityWebApiActivator [assembly

Configure an object provided by a Guice Module

醉酒当歌 提交于 2019-12-20 04:24:40
问题 I have a Module that provides a JDBI DBI instance like this: @Provides @Singleton DBI dbi(DataSource dataSource) { return new DBI(dataSource); } In another module I want to call some initialization methods on that DBI instance (configuring support for particular data types). It's not appropriate logic to put in the JDBI module itself as it's application specific not general to any application using JDBI. Is there a hook for me to do that kind of "extra" configuration? I tried using the

ASP.NET API DI (Simple Injector) null reference on IIS pool recycle

别来无恙 提交于 2019-12-20 04:13:17
问题 I previously posted another question, but after some observations, I have narrowed down to what it may be that's causing my problem. Basically, once the IIS Application Pool is recycled, my dependency injection (which ends up scanning for some DLLs through creating an NWatchApplication), fails. INWatchApplication is a dependency for the Web API project. Here are the contents of the Global.asax: protected void Application_Start() { AreaRegistration.RegisterAllAreas(); GlobalConfiguration

Failure to pass generic arguments with Castle Windsor

允我心安 提交于 2019-12-20 04:11:37
问题 There seems to be an issue with passing generic arguments when attempting to create a parametrized instance with Castle Windsor Demo of Failure to Pass Generic Arguments private static void Main(string[] args) { PassGenericParamAtResolutionTime(); Console.ReadLine(); } private static void PassGenericParamAtResolutionTime() { Console.WriteLine("Passing generic argument fails"); var container = new WindsorContainer(); container.Register(Component.For<ISandCoordinator<Simpleton>>()

Web API, odata v4 and Castle Windsor

喜夏-厌秋 提交于 2019-12-20 03:52:35
问题 I have WebApi project with ODataController and I'm trying to inject some dependency into MyController. I was following this blogpost by Mark Seemann. Consider code below. Problem is, that when is MyController creating, I got exception inside WindsorCompositionRoot Create method on this line, var controller = (IHttpController)this.container.Resolve(controllerType); An exception of type 'Castle.MicroKernel.ComponentNotFoundException' occurred in Castle.Windsor.dll but was not handled in user

how to use scoped dependency in a singleton in C# / ASP

£可爱£侵袭症+ 提交于 2019-12-20 03:43:28
问题 I'm new to C#/ASP coming from a Java world. I've read this article: https://docs.asp.net/en/latest/fundamentals/dependency-injection.html#service-lifetimes-and-registration-options which wisely warns about the dangers associated with injecting a dependency with a smaller scope. Unfortunately it does not explain how to solve this issue in C#/ASP. In Java there's a concept of Provider interface Provider<T> { T get(); } which, among other things helps to solve the scoping issue: whenever a

Angular2 RC BaseRequestOption Constructor Injection

╄→гoц情女王★ 提交于 2019-12-20 03:38:32
问题 I don’t know whether I am missing something but injecting the constructor of a custom baserequestoptions class was working fine for me in Beta 17 but after moving to RC1 this approach doesn’t seem to work any more. I have created a plunkr to illustrate that the webapibaseurl now comes through as undefined (the same code approach but with Beta 17 references worked): https://embed.plnkr.co/usOljRDLap9RlLd3RIBd/ Any ideas? 回答1: This still works for me. Here is the custom option class I used:

What is self-binding in an IoC container?

一世执手 提交于 2019-12-20 03:31:22
问题 I've seen frameworks like Ninject as well as posts on Stack speak about self binding when using dependency injection frameworks like in the code below. Bind<Samurai>().To<Samurai>(); They even go to the extent of having special syntax for this: Bind<Samurai>().ToSelf(); Why would you want to bind a type to itself? I don't see any practical applications for where this might be useful and help reduce dependencies in code. Wouldn't this just mean a reference to a type would simply resolve to