unity-container

Unity - how to use multiple mappings for the same type and inject into an object

不羁的心 提交于 2019-12-05 00:51:36
问题 I'm using Unity 2.0 and in the following code I'm trying to inject a specific tool in the Worker object. I would like to use the following code. But ofcourse there is an error "Resolution of the dependency failed". I believe I should be able to do something like this, but I'm having a difficult time figuring it out. IUnityContainer container = new UnityContainer(); container.RegisterType<IWorker, Worker>("Worker") .RegisterType<ITool, ToolA>("ToolA") .RegisterType<ITool, ToolB>("ToolB")

Using abstract factory as injectionfactory in Unity?

混江龙づ霸主 提交于 2019-12-04 23:51:07
问题 I have an abstract factory registered for injection in some controller instances. Can I register that abstract factory and use it as an injection factory? This is what I have: public interface ILevelFactory { Levels Create(); } .RegisterType<ILevelFactory, LevelFactory>() .RegisterType<Levels>(new InjectionFactory((c) => StaticLevelFactory.GetLevels())) Desired situation: .RegisterType<ILevelFactory, LevelFactory>() .RegisterType<Levels>(*** look up and use ILevelFactory ***) In short, I want

.Net RIA Services: DomainService Needs a Parameterless Constructor?

℡╲_俬逩灬. 提交于 2019-12-04 23:45:18
问题 I'm using the July CTP of .Net RIA Services in an ASP.Net application with some Silverlight components. I'm calling the RIA Services from Silverlight. My problem arose when I tried to use Unity and constructor dependency injection in my Domain Service (a LinqToEntitiesDomainService object). The Silverlight application now complains about not having a parameterless constructor. I don't want to have a parameterless constructor, I want Unity to resolve the constructor arguments. Is this possible

asp.net unity dependency injection doesn't work well

限于喜欢 提交于 2019-12-04 21:50:29
I am using the mvc 3 framework of asp.net, I have created a UnityControllerFactory that implements the IControllerFactory interface: ... public class UnityControllerFactory : IControllerFactory { private IUnityContainer _container; private IControllerFactory _innerFactory; public UnityControllerFactory(IUnityContainer container) : this(container, new DefaultControllerFactory()) { } protected UnityControllerFactory(IUnityContainer container, IControllerFactory innerFactory) { _container = container; _innerFactory = innerFactory; } public IController CreateController(RequestContext

Unity Static Factory Extension

别来无恙 提交于 2019-12-04 21:26:12
问题 I can't seem to find Microsoft.Practices.Unity.StaticFactory.dll anywhere. Is there another way of registering a static factory? Looking for something like this container.RegisterFactory(()=> FooFactory.CreateFoo()); 回答1: StaticFactory.dll was rolled into the main assembly as part of Unity 2.0. It was generally useful enough that we didn't want to force people to carry around a separate DLL just to get it. As such, you can still use the existing API, you just don't need to add the assembly

How to use ReactiveUI inside a PRISM module

ぐ巨炮叔叔 提交于 2019-12-04 19:57:47
We have an existing WPF application that uses PRISM (6.x) with Unity (3.5.x) for DI. We are going to be adding more functionality to this application and would like to start utilizing ReactiveUI for any new modules that we need to implement. We were hoping to minimize the learning curve and continue to utilize Unity and DI for our ViewModels; however, ReactiveUI uses Splat for View location and so far I have not been able to get my ReactiveUI module to actually display in a PRISM region within our main application regardless of what I have tried. The only article that I have really found was

How can I implement Ninject .InSingletonScope() when using Unity IoC

别来无恙 提交于 2019-12-04 18:44:35
I was using ninject IoC in my application and in particular the following: kernel.Bind<RepositoryFactories>().To<RepositoryFactories>() .InSingletonScope(); I would like to implement this using the Unity IoC but can someone tell me how I can make it the same and also what does it mean "InSingletonScope()" ? The following works but I am worried that it's not being done correctly because of the Singleton that maybe needs to be specified. container.RegisterType<RepositoryFactories, RepositoryFactories>(); Unity uses the concept of LifeTimeManager 's.. it comes with what is essentially a Singleton

Automapper and request specific resources

痴心易碎 提交于 2019-12-04 18:19:31
I'm considering automapper for an asp mvc intranet app I am writing. My controllers are currently created using Unity dependency injection, where each container gets dependencies unique to the request. I need to know if automapper can be made to use a request specific resource ICountryRepository to look up an object, like so.... domainObject.Country = CountryRepository.Load(viewModelObject.CountryCode); Couple of options here. One is to do a custom resolver: .ForMember(dest => dest.Country, opt => opt.ResolveUsing<CountryCodeResolver>()) Then your resolver would be (assuming CountryCode is a

Using Unity in WPF

北城以北 提交于 2019-12-04 16:12:53
I have Unity 2.0 working well within the App.xaml.cs to register and resolve within that class. The question I have is regarding a best practice. I have a number of User Controls and other classes that also need to resolve some of the same and new Interface <-> implementations. The problem is theres no way to access the Unity container I created in the App.xaml.cs. I cannot use constructor or property injection to pass on the container reference. Just too many (its a large project) The user controls are added via xaml There are several very loosely related "modules" in the project that can

Using unity xml config to register an interface with nested generics

强颜欢笑 提交于 2019-12-04 13:47:49
问题 If I have a class that implements a generic interface it works fine to configure it using the unity xml config. public interface IReader<T> { } public class Fund { } public class FundReader : IReader<Fund> { } and the unity xml: <unity xmlns="http://schemas.microsoft.com/practices/2010/unity"> <namespace name="System.ComponentModel" /> <namespace name="TestUnityIssue" /> <assembly name="TestUnityIssue" /> <container> <register type="IReader[Fund]" mapTo="FundReader" /> </container> </unity>