unity-container

Prism Module Loading Locks-up Dispatcher Thread. Is There a Way Around This?

若如初见. 提交于 2019-12-01 11:21:52
问题 The Prism application I have performs multiple startup tasks that can take a while and if some of those tasks fail to execute properly it will make the application functionally unusable. Because of this, I have a startup screen that displays before the Shell and shows a log of the status of each startup task. (The startup tasks are handled by a shared service in a module.) The screen includes a ProgressBar with IsIndeterminate set to True (at least while the startup tasks are running). I also

What should be injected as C'tor paramter under DI principles?

醉酒当歌 提交于 2019-12-01 09:43:48
问题 I'm trying to understand which objects should be injected into an object and which should be created internally. If i have some List<int> (as data field) which holds infomation gathered during run time. it seems that i should init it in the c'tor instead of injecting it. but what about a hardware class which communicates through a COM port. do i let the HW class init the SerialPort or i inject it ? If the above mentioned SerialPort needs to be injected; what is the best way to do it ? do i

Is it possible to deduplicate registration in unity?

荒凉一梦 提交于 2019-12-01 09:15:21
问题 Consider interfaces: public interface IOne{} public interface ITwo{} public interface IBoth : IOne, ITwo{} And class public class Both : IBoth{} But when I need to resolve base interfaces I need to register both interfaces in container <register type="IOne" MapTo="Both"/> <register type="ITwo" MapTo="Both"/> The question is - can I deduplicate the registration in a way like this: <register type="IBoth" MapTo="Both"/> But resolve it in different places from different interfaces: var o =

Prism 6 with Unity - resolving view models for views without naming convention

喜欢而已 提交于 2019-12-01 07:55:34
问题 I am trying to have view models resolved using DI with Prism 6 and Unity in my WPF app and this works. However I don't know how to tell the framework which view should be merged with which view model. If I use the convention, i.e. have ViewModels, and Views namespaces, and classes ViewA and ViewAViewModel everything works, however I would like to have more flexibility to name and organize my classes and this is why I want to somehow tell the framework explicitly which view goes with which

Accessing unity container in view model class

会有一股神秘感。 提交于 2019-12-01 07:47:29
问题 I have a shell which looks like toolbar and defines my main region (a wrap panel). What I need to do is be able to add widgets to the shell and when a widget is clicked, a new window (view) is opened. Below is what I have so far: I created a module class which adds a view to the main region: public class MyModule : IModule { protected IUnityContainer Container { get; private set; } public MyModule(IUnityContainer container) { Container = container.CreateChildContainer(); } public void

Unity register generic type for non generic interface

冷暖自知 提交于 2019-12-01 06:48:01
my scenario looks (to me) very straight forward, but I couldn't find a resolution. I have this scenario public class Class<T> : IInterface where T : class { } the interface cannot be made generic (coming from WCF lib.) so I want to register the interface like this container.RegisterType(typeof (IInterface ), typeof (Class<>)); and then resolve it with T How can I do it? What am I missing? my intention is doing something like container.Resolve<IInterface>(/* specify T */); If you don't need to resolve using the uncontrolled interface, you can make your own controlled interface which uses

MVC3, Unity Framework and Per Session Lifetime Manager Issue

送分小仙女□ 提交于 2019-12-01 06:42:15
In a simple word I try to create Lifetime manager for Unity framework by using Http Session in my MVC3 project. My sample implementation of lifetime manager is: public class UnityPerSessionLifetimeManager : LifetimeManager { private string sessionKey; private HttpContext ctx; public UnityPerSessionLifetimeManager(string sessionKey) { this.sessionKey = sessionKey; this.ctx = HttpContext.Current; } public override object GetValue() { return this.ctx.Session[this.sessionKey]; } public override void RemoveValue() { this.ctx.Items.Remove(this.sessionKey); } public override void SetValue(object

Unity register generic type for non generic interface

半城伤御伤魂 提交于 2019-12-01 06:03:40
问题 my scenario looks (to me) very straight forward, but I couldn't find a resolution. I have this scenario public class Class<T> : IInterface where T : class { } the interface cannot be made generic (coming from WCF lib.) so I want to register the interface like this container.RegisterType(typeof (IInterface ), typeof (Class<>)); and then resolve it with T How can I do it? What am I missing? my intention is doing something like container.Resolve<IInterface>(/* specify T */); 回答1: If you don't

Generic dependency injection with Unity

一个人想着一个人 提交于 2019-12-01 05:21:00
问题 We are wrapping an existing logging library in our own logging service in a C# application to surround it with predefined methods for certain logging situations. public class LoggingBlockLoggingService : ILoggingService { private LogWriter writer; public LoggingBlockLoggingService(LogWriter writer) { this.writer = writer; } ....//logging convenience methods, LogWarning(), etc... } I would like to modify this implementation so that it takes in the Type of the class that instantiates it (the

How to conditionally bind a instance depending on the injected type using unity?

走远了吗. 提交于 2019-12-01 05:12:19
I'm used to Ninject, and for a specific project I'm asked to learn Unity. There is one thing i can't find information on how to do. In Ninject I can state: Bind<IWarrior>().To<Samurai>().Named("Samurai"); Bind<IWarrior>().To<Ninja>().Named("Ninja"); Bind<IWeapon>().To<Katana>().WhenInjectedInto(typeof(Samurai)); Bind<IWeapon>().To<Shuriken>().WhenInjectedInto(typeof(Ninja)); And then when one asks for the warrior named samurai, the samurai comes with kanana and the ninja comes with shurikens. As it should. I don't want to reference the container in the warriors to get the appropriate weapon,