inversion-of-control

How to set Class<?> as property value in spring application context?

时光总嘲笑我的痴心妄想 提交于 2020-01-03 18:18:31
问题 Is there a way to configure spring application context so it will initialize the setter with value of type Class? I need to initialize that structure: Map<Class<?>, Object> 回答1: Have you tried something like this: <bean id="myBean" class="myBean"> <!-- This will set a map onto the property classMap of myBean --> <property name="classMap"> <map key-type="java.lang.Class"> <entry key="java.lang.String" value="A String keyed by the class 'java.lang.String'" /> </map> </property> </bean> 来源:

Project-Embedded IoC Container

前提是你 提交于 2020-01-03 10:58:12
问题 I am looking for a really simple and lightweight IoC Container whose C# source can be included in my own project (thus not making an external reference). The reason for this is that I am writing an infrastructure and would like to provide a single .dll file, without any additional dependencies. I also do not want to ILMerge my assembly with the IoC assembly.. I thought about MEF, some other suggestions? 回答1: If you're using .NET 4.0 you have MEF included. For .NET 2 I once wrote something

Project-Embedded IoC Container

耗尽温柔 提交于 2020-01-03 10:58:05
问题 I am looking for a really simple and lightweight IoC Container whose C# source can be included in my own project (thus not making an external reference). The reason for this is that I am writing an infrastructure and would like to provide a single .dll file, without any additional dependencies. I also do not want to ILMerge my assembly with the IoC assembly.. I thought about MEF, some other suggestions? 回答1: If you're using .NET 4.0 you have MEF included. For .NET 2 I once wrote something

How to create a Spring bean from a static inner class constructor?

百般思念 提交于 2020-01-03 08:55:10
问题 I am trying to use the Spring Framework IoC Container to create an instance of class ThreadPoolExecutor.CallerRunsPolicy. In Java, I'd do it this way... import java.util.concurrent.RejectedExecutionHandler; import java.util.concurrent.ThreadPoolExecutor; ... RejectedExecutionHandler rejectedExecutionHandler = new ThreadPoolExecutor.CallerRunsPolicy(); But when I try to do the equivalent in Spring, it throws a CannotLoadBeanClassException . <beans> <bean class="java.util.concurrent

Castle Windsor DI installer: dependency factory method has nested dependency on ApiController property

你说的曾经没有我的故事 提交于 2020-01-03 05:18:08
问题 I am trying to implement DI with Castle Windsor. Currently I have a controller with overloaded constructors like this (this is an antipattern as described here: https://www.cuttingedge.it/blogs/steven/pivot/entry.php?id=97): public class MyController : ApiController { protected IStorageService StorageService; protected MyController() { StorageService = StorageServiceFactory.CreateStorageService(User.Identity as ClaimsIdentity); } protected MyController(IStorageService storageService) {

MVC and dependency injection, forced to use singleton Controller?

两盒软妹~` 提交于 2020-01-02 07:33:10
问题 I'm working on building a PHP framework that behaves according to MVC principles and utilizes dependency injection. I think I have the front-controller part down; there is a working router that instantiates a controller instance and calls the appropriate action based on the requested URI. Next up is dependency injection. I want to implement a Container that resolves dependencies using reflection. In doing so, I think I'm running into a problem with my controllers. There are a number of what I

UnityContainer configured in web.config

狂风中的少年 提交于 2020-01-02 07:21:12
问题 I have the following code var container = new UnityContainer(); //LINE 1 container.RegisterType<ILogUtility,LogUtil>(); //LINE 2 var logger = container.Resolve<Logger>(); //LINE 3 logger.Log(LogType.Warn, "logging from container"); //LINE 4 How do I implement line 2 in web.config such that I will only have to code line 1, 3, and 4 in my code behind? I have searched every where for code example but they are not clear. Thanks 回答1: Take a look at my tutorial http://netpl.blogspot.com/2011/11

Confused over using IOC container, service locator and factory

為{幸葍}努か 提交于 2020-01-02 06:45:30
问题 Suppose I have a BaseForm which depends on an ILogger or IResourceManager or something like that. Currently it resolves the correct implementation of the required service using the service locator which I know is an anti-pattern. Is using the constructor injection the right way to resolve this kind of dependency? Do I have to register my BaseForm (and its' derived types) in the container in order to create instances of them with resolved dependencies? Doesn't that complicate everything? Is it

Register Generic Type in Unity Based On Concrete Type

爷,独闯天下 提交于 2020-01-02 06:29:23
问题 I'm trying to emulate a behavior that I can configure in Ninject, only using Unity instead. I am attempting to use the Cached Repository Pattern, given the following classes and interface: public interface IRepository<T> { T Get(); } public class SqlRepository<T> : IRepository<T> where T : new() { public T Get() { Console.WriteLine("Getting object of type '{0}'!", typeof(T).Name); return new T(); } } public class CachedRepository<T> : IRepository<T> where T : class { private readonly

TinyIoC: Register multiple interfaces on a single instance

给你一囗甜甜゛ 提交于 2020-01-02 01:30:08
问题 Autofac allows resolving multiple interfaces to the same instance very easily with .AsImplementedInterfaces() or chained .As<>() calls together with .SingleInstance(). Can this also be done with TinyIoC? I've only found how to register multiple implementations of the same interface, but there is no way of chaining registrations or the like. From my understanding this is a quite important feature for an IoC container, isn't it? 回答1: If I'm understanding correctly you have something like public