unity-container

Getting Started with Unity Framework [closed]

生来就可爱ヽ(ⅴ<●) 提交于 2019-11-29 20:00:45
Could anyone recommend some good resources for getting started with the Unity framework ? I've downloaded the source from Codeplex and got it to compile. So now I've got a set of compiled binaries, where do I go next? I understand the principles of inversion of control but don't have much knowledge of the specifics of the Unity framework. I've downloaded the Unity documentation from Codeplex but it seems to be targeted at users that already have a good working knowledge of the framework. What I'm really looking for is some good "getting started" type guides for Unity, or maybe some basic

What is different between and purpose of MEF and Unity?

和自甴很熟 提交于 2019-11-29 19:51:37
I just start study DI (I'm working on WPF/Silverlight but I have a plan to move to ASP.NET). After I read some DI articles from internet there are two Frameworks that I'm interested in, MEF and Unity. I want to know what is the real-world different between them and which one is good to go. The main difference is that with unity you will explicitly register each class you want to use in the composition: var container = new UnityContainer(); container.RegisterType<IFoo,Foo>(); container.RegisterType<IBar,Bar>(); ... var program = container.Resolve<Program>(); program.Run(); In MEF on the other

IUnityContainer.Resolve<T> throws error claiming it cannot be used with type parameters

别等时光非礼了梦想. 提交于 2019-11-29 19:30:44
Yesterday I've implemented the code: CustomerProductManager productsManager = container.Resolve<CustomerProductManager>(); It was compilable and working. Today (probably I've modified something) I am constantly getting the error: The non-generic method 'Microsoft.Practices.Unity.IUnityContainer.Resolve(System.Type, string, params Microsoft.Practices.Unity.ResolverOverride[])' cannot be used with type arguments My collegue has the same source code and doesn't have same error. Why? How to resolve the problem? P.S. line "using Microsoft.Practices.Unity;" is present in usings section. I've tried

Is it possible to get current Unity container inside controller

大城市里の小女人 提交于 2019-11-29 19:29:31
问题 I registered unity container like this: var container = new UnityContainer(); container.RegisterType<ICacheManager, CacheManager>(new ContainerControlledLifetimeManager()) Is it possible to get access to this "container" from controller 回答1: One way of doing this which I often do for convenience is to declare your container as a global variable in your Global.ascx.cs file like: public class MvcApplication : System.Web.HttpApplication { public static UnityContainer Container; protected void

Unity PerRequestLifetimeManager re-using object in different requests

放肆的年华 提交于 2019-11-29 19:13:35
问题 I've set up Unity for dependency injection for our project. The project itself is an ASP.NET application that uses both MVC and Web API. For the database context, I'm using the PerRequestLifetimeManager . This is done so that the different bits of business logic are using the same context (and thus the same transaction). In order to be able to use the PerRequestLifetimeManager , I've added references to the nuget packages Unity bootstrapper for ASP.NET MVC and Unity bootstrapper for ASP.NET

Unity 3 and Error “The type name or alias ”xxxxx“ could not be resolved. Please check your configuration file and verify this type name.”

假装没事ソ 提交于 2019-11-29 19:08:17
问题 Is there any way to resolve this problem with Unity 3 ? I have made all that is possible to bypass this message error, but I can't resolve; I have already did everything I've seen in googles searches. I am almost giving up and trying another DI solution. My configuration file: <?xml version="1.0" encoding="utf-8" ?> <configuration> <configSections> <section name="unity" type="Microsoft.Practices.Unity.Configuration.UnityConfigurationSection, Microsoft.Practices.Unity.Configuration" /> <

How do I use a Unity IoC container with Template10?

浪尽此生 提交于 2019-11-29 18:56:48
问题 I have an app based on Template10 and want to handle my dependency injection using IoC. I am leaning toward using Unity for this. My app is divided into three assemblies: UI (Universal app) UI Logic (Universal Library) Core Logic (Portable Library). I have these questions: Should I use a single container for the whole app, or create one for each assembly? Where should I create the container(s) and register my services? How should different classes in the various assemblies access the

DI with Unity when multiple instances of the same type is needed

陌路散爱 提交于 2019-11-29 18:38:55
问题 I need help with this. I'm using Unity as my container and I want to inject two different instances of the same type into my constructor. class Example { Example(IQueue receiveQueue, IQueue sendQueue) {} } ....and IQueue is implemented in my MessageQueue class.... class MessageQueue : IQueue { MessageQueue(string path) {} } How can I inject two different instances of MessageQueue into my Example class? Each of the MessageQueue instances to be created with different path. 回答1: There are many

Custom object factory extension for Unity

允我心安 提交于 2019-11-29 18:22:52
问题 I am using the Unity IoC container, and I need to intercept any calls to Resolve for a certain base interface, and run my own custom code to construct those types. In other words, in the sample code below, when I call container.Resolve<IFooN>() , if it hasn't got an instance of the concrete implementing type, it calls MyFactoryFunction to construct one, otherwise I want it to return the cached copy. The standard Unity container is not able to construct these objects ( update: because they are

How to resolve dependency in static class with Unity?

∥☆過路亽.° 提交于 2019-11-29 16:58:15
问题 I have the following extension method, which exists (naturally) in a static class. public static class MyExtensions { [Dependency] private static IMyDataContext _myDataContext { get; set; } public static void MyExtensionMethod(this MyType myType) { // do stuff _myDataContext.DoAwesomeThing(); } } the _myDataContext object is null . Normally I'd use the UnityContainer to register the type, but as this is a static class, I can't. What do I need to instantiate _ myDataContext so that it's not