unity-container

Injecting a property into a singleton service in Prism (Unity, MVVM)

删除回忆录丶 提交于 2020-01-17 04:26:45
问题 For reference, I have a service that I want to register as a singleton in the unity container. I want this service to have the IEventAggerator injected into the service somehow, either by property or constructor injection. public class BeckhoffService: IProgrammableLogicController { ...} and I'll either want this: [Dependency] public IEventAggregator eventAggregator{get;set;} or in the constructor: BeckhoffService(IEventAggregator eventAggregator) My issue comes when I register this service

How to resolve Dependency within Dependency

…衆ロ難τιáo~ 提交于 2020-01-17 04:11:10
问题 I have 4 Projects in a solution DAL_Project BLL_Project Interface_Project WebApi_Project Interface_Project has two interfaces ICar_DAL and ICar_BLL DAL_Project has a class Car_DAL that implements ICar_DAL BLL_Project has a class Car_BLL that implements ICar_BLL and its constructor takes in ICar_DAL WebApi_Project has an api controller CarApiController and its constructor takes in ICar_BLL the dependency resolution of WebApi Controller's constructor is done by Unity.WebApi using this in

Does it make sense to check for null values in injected arguments?

狂风中的少年 提交于 2020-01-15 21:17:32
问题 I am using Unity in my application. Does it make sense to check for null values in the constructor for the injected values? public class ExampleClass { public ExampleClass(IExampleArgument e) { if (e == null) //Do something } } Shouldn't the argument be resolved already and bound to a value? And in case a problem happens, it should occur during resolving, so I either have a value here or I don't? 回答1: Does it make sense to check for null values in the constructor for the injected values?

Does it make sense to check for null values in injected arguments?

走远了吗. 提交于 2020-01-15 21:17:17
问题 I am using Unity in my application. Does it make sense to check for null values in the constructor for the injected values? public class ExampleClass { public ExampleClass(IExampleArgument e) { if (e == null) //Do something } } Shouldn't the argument be resolved already and bound to a value? And in case a problem happens, it should occur during resolving, so I either have a value here or I don't? 回答1: Does it make sense to check for null values in the constructor for the injected values?

When should my prism services be registered?

不羁的心 提交于 2020-01-15 16:40:52
问题 I've been struggling with the ideal approach to this. Right now, I have my services created in Boostrapper right before I create my application shell, in the method: protected override DependencyObject CreateShell() After my shell gets created, I then create all my view models, passing the services they need. So firstly, I want to know if that's a good practice. Also, I've tried to find examples of declaring services inside a .config file, but I really didn't see any. Is this not a good

How to use dependency injection in ActionFilter Web API?

坚强是说给别人听的谎言 提交于 2020-01-15 09:56:52
问题 I am trying to get work with dependency injection into the action filter, but it seems not working I've registered the type in UnityConfig public static void RegisterComponents(IUnityContainer container) { GlobalConfiguration.Configuration.DependencyResolver = new UnityDependencyResolver(container); container.RegisterType<Domain.Contracts.IUserServices, Domain.UserServices>(new ContainerControlledLifetimeManager()); ... } The code is being called successfully, however, the instantiated object

Use Prism.Unity.UnityBootstrapper with Unity.IUnityContainer

随声附和 提交于 2020-01-14 14:11:48
问题 I’ve upgraded my project today to Prism 6.3.0 and Unity 5.3.1. Before that, I had Prism 5 and Unity 4. Now I’m running into problems with the Prism.Unity.UnityBootstrapper : it seems that the Container field is still a Microsoft.Practices.Unity.IUnityContainer instead of Unity.IUnityContainer . I had hoped that the upgrade would cleanly cut all references to Microsoft.Practices.Unity off of my project, but it seems that I’m still forced to use the “old” Prism library, at least in parts. Why

Unity Factory Injection

爱⌒轻易说出口 提交于 2020-01-14 13:08:32
问题 I have an interface like the below one which I inject into unity container. public interface IMyInstanceFactory { IEnumerable<IMyInstance> GetAll(); } All IMyInstance are known before runtime i.e they can be setup within the bootstrapper and can be retrieved from unity. My concrete implementation for IMyInstanceFactory is as below: public class MyInstanceFactory:IMyInstanceFactory { IUnityContainer _container; public MyInstanceFactory(IUnityContainer container) { _container = container; }

Unity Factory Injection

倾然丶 夕夏残阳落幕 提交于 2020-01-14 13:07:13
问题 I have an interface like the below one which I inject into unity container. public interface IMyInstanceFactory { IEnumerable<IMyInstance> GetAll(); } All IMyInstance are known before runtime i.e they can be setup within the bootstrapper and can be retrieved from unity. My concrete implementation for IMyInstanceFactory is as below: public class MyInstanceFactory:IMyInstanceFactory { IUnityContainer _container; public MyInstanceFactory(IUnityContainer container) { _container = container; }

Unity - ResolveAll by name with condition

霸气de小男生 提交于 2020-01-13 16:29:14
问题 I was wondering if it is possible to resolve all dependancies in Unity by some condition on the name that they were registered. For example: Resloving all interfaces registered where the name registered starts with "ProcessA". And if there is no way to do this then perhaps how can i extend Unity to allow this. 回答1: You should be able to use Registrations to do this and I would recommend an extension method rather than extending Unity directly: var matches = c.Resolve<IMyService>(name => name