unity-container

AutoMapper registration in Unity DI

[亡魂溺海] 提交于 2020-01-13 04:55:21
问题 I'm not that familiar with Unity or StructureMap. How do you convert the following StructureMap registration sample into Unity registration syntax? public class ConfigurationRegistry : Registry { public ConfigurationRegistry() { ForRequestedType<ConfigurationStore>() .CacheBy(InstanceScope.Singleton) .TheDefault.Is.OfConcreteType<ConfigurationStore>() .CtorDependency<IEnumerable<IObjectMapper>>().Is(expr => expr.ConstructedBy(MapperRegistry.AllMappers)); ForRequestedType

ASP.NET Identity's UserManager caches users?

[亡魂溺海] 提交于 2020-01-11 09:12:48
问题 We're using ASP.NET Identity 2.2 with ASP.NET MVC 5.2, Entity Framework 6.2 and Unity 5.7. We have a class, ConnectUserManager , that derives from ASP.NET Identity's UserManager . A newly constructed UserStore is passed to UserManager every time. The lifetime of ConnectUserManager (and thus of UserManager ) is per request: Container.RegisterType<ConnectUserManager>( new PerRequestLifetimeManager(), new InjectionConstructor( Container.Resolve<ConnectDbContext>(), Container.Resolve

Unity resolving cyclic dependency

女生的网名这么多〃 提交于 2020-01-11 04:47:07
问题 While learning Unity (DI framework in C# ) I came across a situation where one class has a setter injection of ClassB class ClassA : IClassA { [Dependency] public IClassB ClassB { get { return _classB; } set { if (value == null) throw new ArgumentNullException("value"); _classB = value; } } and the other has a constructor injection of the ClassA class ClassB : IClassB { [InjectionConstructor] public ClassB(IClassA classA) { _classA = classA; } } I am not able to resolve both the classes

Unity Interception in Derived Class

我怕爱的太早我们不能终老 提交于 2020-01-07 07:21:03
问题 I've got a situation where policy injection no longer works when I'm using a derived class. The classes involved look like this (basically an interface, an abstract base class, and an implementation class): public interface IRepository<T> { void Create(T iItem); } public abstract class ElmtRepository<T> : IRepository<T> { protected List<T> Items { get; set; } public ElmtRepository() { Items = new List<T>(); } public void Create(T iItem) { Items.Add(iItem); } } public class AcctPgmRepository :

Prism MVVM - How to pass an IEventAggregator to my ViewModel

◇◆丶佛笑我妖孽 提交于 2020-01-07 04:14:13
问题 recently I started working with Prism in Silverlight. I want to use the EventAggregator to Subscribe and Publish events between two ViewModels. As I saw on some guides, the ViewModel's ctor should accept IEventAggregator as a parameter. I can't find out how to do this hence my View always wants to initialize the ViewModel with a parameterless ctor. My ViewModel ctor: MyViewModel(IEventAggregator eventAggregator) { // get the event.... } My View: <UserControl ....> <UserControl.Resources>

The type 'InversionOfControl.IOC' exists in both 'InversionOfControl.dll' and 'InversionOfControl.dll'

雨燕双飞 提交于 2020-01-07 03:58:28
问题 I have a project called InversionOfControl . That project has a class called IOC . It looks like this: /// <summary> /// This class is used to expose the unity container to the application. /// </summary> public class IOC { /// <summary> /// The actual unity container for the app. /// </summary> public static IUnityContainer Container { get; set; } } All my projects that need to resolve unity injections have a reference to this class. Lately I have started getting this error: Value cannot be

How does IoC container know which named instance to inject?

╄→尐↘猪︶ㄣ 提交于 2020-01-05 04:09:06
问题 When there are multiple named implementations for a given interface, how does the container (I am using Unity in a Prism application) know which one to inject unless I call the container.Resolve with the registered name? Here is a simple example: public interface IDependencyClass { void DoSomething(); } public class DependencyClassA : IDependencyClass { void DoSomething() { } } public class DependencyClassB : IDependencyClass { void DoSomething() { } } public interface IConsumer { void

How to Solve Circular Dependency

给你一囗甜甜゛ 提交于 2020-01-04 06:55:07
问题 Hi I have a problem with the structure of my code, it somehow goes into Circular Dependency. Here is an explanation of how my code looks like: I have a ProjectA contains BaseProcessor and BaseProcessor has a reference to a class called Structure in ProjectB . Inside BaseProcessor , there is an instance of Structure as a variable. In projectB there are someother classes such as Pricing , Transaction etc. Every class in ProjectB has a base class called BaseStructure i.e. Structure , Pricing and

Resolving named registration using Unity 2 in DefaultControllerFactory

橙三吉。 提交于 2020-01-04 06:06:09
问题 I have an issue with resolving named registrations of registered types in Unity 2 using ASP.NET MVC 3 with DI set in DefaultControllerFactory. In one assembly I have defined Unity container with registration types and named registrations public class VisUnityContainer : UnityContainer { public IUnityContainer RegisterVisComponents() { // register types this .RegisterType<ICompanyService, CompanyService>() .RegisterType<ICompanyService, TestCompanyService>( "2" ); } } and in my MVC project I

Resolving named registration using Unity 2 in DefaultControllerFactory

纵饮孤独 提交于 2020-01-04 06:05:18
问题 I have an issue with resolving named registrations of registered types in Unity 2 using ASP.NET MVC 3 with DI set in DefaultControllerFactory. In one assembly I have defined Unity container with registration types and named registrations public class VisUnityContainer : UnityContainer { public IUnityContainer RegisterVisComponents() { // register types this .RegisterType<ICompanyService, CompanyService>() .RegisterType<ICompanyService, TestCompanyService>( "2" ); } } and in my MVC project I