dependency-injection

ASP.NET MVC 3 Dependency Injection - Controllers, Views & Action Filters

南笙酒味 提交于 2019-12-21 12:22:35
问题 I'm trying to get dependency injection working in an ASP.NET MVC 3 application using Microsoft Unity. First i have implemented my own IDependencyResolver and activated it in my Global.asax file like so: DependencyResolver.SetResolver(new UnityDependencyResolver(container)); I found that i don't need to do anything else to get controller injection (via both the constructor and [Dependency] attribute) to work. With the default view engine i also found i could get the [Dependency] attribute to

Bind list of objects using Guice + Kotlin

吃可爱长大的小学妹 提交于 2019-12-21 11:55:14
问题 I'm writing a JavaFX application in Kotlin with the following controller definition: class MainController { @Inject private lateinit var componentDescriptors: List<ComponentDescriptor> /* More code goes here */ } I'm using Guice for Dependency management. And I'm trying to inject the list of class instances loaded via java.util.ServiceLoader . My problem is to define a binding that will inject the list of loaded object instances into the declared field. I tried annotation based provisioning:

Problem instantiating generic class bean in Spring

扶醉桌前 提交于 2019-12-21 11:45:43
问题 I'm trying to instantiate a generic class in Spring, but I get following exception: Initialization of bean failed; nested exception is org.springframework.aop.framework.AopConfigException: Could not generate CGLIB subclass of class [class football.dao.jpa.GenericJpaDAO]: Common causes of this problem include using a final class or a non-visible class; nested exception is java.lang.IllegalArgumentException: Superclass has no null constructors but no arguments were given: This is the XML

Can CDI be lessened towards Java SE?

China☆狼群 提交于 2019-12-21 11:28:35
问题 JSR-330 dependency injection can be applied to both Java SE and Java EE environments, while JSR-299 is titled "Contexts and Dependency Injection for the Java EE platform". Except strictly Java EE-oriented features, what CDI features make sense on Java SE as well? Any examples available? Thanks! [Revised] Here's Weld on JSE. 回答1: Except strictly Java EE-oriented features, what CDI features make sense on Java SE as well? Any examples available? Thanks! Well, the one mentioned in the Weld

Dependency Injection on AuthorizationOptions

时光总嘲笑我的痴心妄想 提交于 2019-12-21 09:24:24
问题 I am creating an authorization rule/policy for my ASP.NET 5 MVC application. Creating it was straightforward and pretty easy to do, and it is working (with my basic tests). However, I now need to get my data context into the requirement. I created a constructor in my IAuthorizationRequirement implementation which takes a MyContext object which implements DbContext . I am registering the IAuthorizationRequirement like so in my Startup.cs file. services.Configure<AuthorizationOptions>(options =

Why getting multiple instances of IMemoryCache in ASP.Net Core?

南楼画角 提交于 2019-12-21 09:19:15
问题 I have what I believe is a standard usage of IMemoryCache in my ASP.NET Core application. In startup.cs I have: services.AddMemoryCache(); In my controllers I have: private IMemoryCache memoryCache; public RoleService(IMemoryCache memoryCache) { this.memoryCache = memoryCache; } Yet when I go through debug, I end up with multiple memory caches with different items in each one. I thought memory cache would be a singleton? Updated with code sample: public List<FunctionRole> GetFunctionRoles() {

Guice proxying to support circular dependency

早过忘川 提交于 2019-12-21 08:25:44
问题 I'm getting the following error in my code at launch: Tried proxying com.bar.Foo to support a circular dependency, but it is not an interface. How exactly does this proxying work? If I just throw enough classes behind interfaces, will everything be fine? (I know that circular dependencies are usually a code smell, but I think in this case it's ok.) 回答1: While the "inject an interface" approach is totally valid, and might even be the better solution in some occasions, in general, you can use a

Guice proxying to support circular dependency

做~自己de王妃 提交于 2019-12-21 08:24:48
问题 I'm getting the following error in my code at launch: Tried proxying com.bar.Foo to support a circular dependency, but it is not an interface. How exactly does this proxying work? If I just throw enough classes behind interfaces, will everything be fine? (I know that circular dependencies are usually a code smell, but I think in this case it's ok.) 回答1: While the "inject an interface" approach is totally valid, and might even be the better solution in some occasions, in general, you can use a

Beside testing, why do we need Dagger 2?

久未见 提交于 2019-12-21 07:45:39
问题 At this point, my understanding of Dependency Injection (DI) is only from this article. I'm interested to try, but I just need to clarify some things: Many refer DI as a tool to reduce boilerplate code. But according to that tutorial, the setup of Dagger 2 tends to create even more classes for configuration (module and component). I have not tried it, but by the looks of it, it isn't reducing the code, it is just splitting them so the main class can look tidier. Am I wrong on this one?

Beside testing, why do we need Dagger 2?

三世轮回 提交于 2019-12-21 07:44:48
问题 At this point, my understanding of Dependency Injection (DI) is only from this article. I'm interested to try, but I just need to clarify some things: Many refer DI as a tool to reduce boilerplate code. But according to that tutorial, the setup of Dagger 2 tends to create even more classes for configuration (module and component). I have not tried it, but by the looks of it, it isn't reducing the code, it is just splitting them so the main class can look tidier. Am I wrong on this one?