inversion-of-control

Why is the _bin_DeployableAssemblies folder specific to web applications?

被刻印的时光 ゝ 提交于 2019-12-20 02:55:32
问题 The _bin_DeployableAssemblies folder was added in VS 2010 SP1 as a common way to pull in assemblies for which no hard dependency exists. I believe it was originally added as a way to allow folks to bin-deploy MVC, but it seems useful in environments outside of web applications. In particular, a lot of inversion of control scenarios will result in loosely coupled components that don't require a hard reference, but still require dependent assemblies to be located (usually in the bin directory).

Windsor Castle :- Inject Dictionary of Interfaces via configuration

我是研究僧i 提交于 2019-12-20 02:34:20
问题 Hi i am trying to inject a dictionary of interfaces but am getting an error from castle like this :- Castle.MicroKernel.SubSystems.Conversion.ConverterException: No converter registered to handle the type IFoo In order to go around the exception, I had to create a wrapper that contained a list of the Ifoo interface and returns it using a property. The wrapper was then used in the configuration ==> dictionary instead of dictionary Is there a way in castle that I can just have a dictionary of

polymorphic resolution of generic parameters in Unity registerType

僤鯓⒐⒋嵵緔 提交于 2019-12-20 02:27:41
问题 I am trying to do the following and failing: class base {} class derived1 : base {} class derived2 : base {} interface itr<t> where t : class, base {} class c1: itr<derived1> {} class c2 : itr<derived2> {} //The following 2 registrations fail: _unityContainer.RegisterType<itr<base>, c1>("c1"); _unityContainer.RegisterType<itr<base>, c2>("c2"); The error I get is that the second parameter in the above registrations cannot be typecast into the first parameter and this registration is not valid.

Where is the composition root in a WPF MDI application?

佐手、 提交于 2019-12-19 21:47:26
问题 In traditional MDI applications some objects (Forms) will be created when a command occurs (Ex. pressing a ribbon button), so it maybe a composition point. I'm confiused about composition root in such applications. I read somewhere that we can use a ViewModelLocator which looks like Service Locator pattern. As you know the service locator pattern is denounced by some people. Now please advice me about this issue. Thanks in advance. 回答1: Whether or not a ViewModelLocator is a Service Locator

Unity Batch Register by convention

时光怂恿深爱的人放手 提交于 2019-12-19 11:49:20
问题 I'm trying to do the equivalent of the following Autofac code in Unity IoC. builder.RegisterAssemblyTypes(typeof (DataRepository<>).Assembly) .Where(t => t.Name.EndsWith("Repository")) .AsImplementedInterfaces(); This basically replaces individually registering the following: DataSourceDataRepository : DataRepository<DataSource>, IDataSourceDataRepository For clarity: This registers all of my Repository types as their implemented interfaces, so when i inject IDataSourceDataRepository I get a

How to declare the Unity InjectionFactory in XML configuration

 ̄綄美尐妖づ 提交于 2019-12-19 06:17:29
问题 I'm in the process of moving our Unity configuration to the web.config file. I'm stuck on how to migrate the following code config to the xml format: var container = new UnityContainer(); container.RegisterType<IPrincipal>(new InjectionFactory(x=> HttpContext.Current.User)); return container; Here are the XML declartion: <unity xmlns="http://schemas.microsoft.com/practices/2010/unity"> <alias alias="IRepository" type="Model.IRepository, Model" /> <alias alias="Repository" type="Data

Setting up Inversion of Control (IoC) in ASP.NET MVC with Castle Windsor

好久不见. 提交于 2019-12-19 05:58:53
问题 I'm going over Sanderson's Pro ASP.NET MVC Framework and in Chapter 4 he discusses Creating a Custom Controller Factory and it seems that the original method, AddComponentLifeStyle or AddComponentWithLifeStyle , used to register controllers is deprecated now: public class WindsorControllerFactory : DefaultControllerFactory { IWindsorContainer container; public WindsorControllerFactory() { container = new WindsorContainer(new XmlInterpreter(new ConfigResource("castle"))); // register all the

Can any of existing IoC containers create the lazy proxy classes dynamically?

夙愿已清 提交于 2019-12-19 04:07:14
问题 I study different DI patterns. And now I interested in the lazy life-time implementation. For example, I want to write a proxy class that hides the factory behind a service's interface. Can any of existing IoC containers (.NET) create this kind of proxy class dynamically at runtime? interface IService { void Foo(); void Bar(); } class ServiceFactoryProxy : IService { private readonly Func<IService> _factory; public ServiceFactoryProxy(Func<IService> factory) { if (factory == null) throw new

Implementing repository for EF4 using DDD and IoC

这一生的挚爱 提交于 2019-12-19 03:24:07
问题 I think I'm going in circles. I'm working on an MVC 3 solution using EF4 & POCOs (database-first) and IoC. My repository and UoW patterns were mostly adopted from this article and this article. My solution is made up of the following projects: Implementations: Presentation (MVC site) Domain Services (business layer) Domain Repository (data access) Domain Context (my EF4 edmx and generated context) Domain Models (my EF4 generated POCOs) Interfaces: Domain Services Interfaces (business layer

Dynamic selection of interface implementation using IoC

时间秒杀一切 提交于 2019-12-19 03:13:24
问题 I have a situation where the implementation of an interface is determined at runtime. For example, I check a string and then determine which subclass to use, without IoC it looks like the following: if (fruitStr == "Apple") { new AppleImpl().SomeMethod(); } else { new BananaImpl().SomeMethod(); } Both classes AppleImpl and BananaImpl are implementation of the same interface, say IFruit . How can this be done using IoC/Dependency Injection, especially in Castle Windsor ? 回答1: This is the