unity

Rational use of unity and service locator pattern

Hello! I've recently introduced to unity block and to DI and ServiceLocator patterns. It seems to have sense, but on practice some questions concerned about its rational use arise. I mean, that I've came to unity from articles about service locator, which is used to decouple classes realize some functionality (services) from classes th...

Auto inject property for register types without DependencyAttribute.

Register<IA, A>(); class B { public IA A {get;set;}} //container inject this property because IA was registered In autofac you can do builder.RegisterType<A>().InjectProperties(); for this. Is there any extension for unity to do this? Or may be extension which I can use as sample for implement this feature by myself? ...

How do I correctly use Unity to pass a ConnectionString to my repository classes?

I've literally just started using the Unity Application Blocks Dependency Injection library from Microsoft, and I've come unstuck. This is my IoC class that'll handle the instantiation of my concrete classes to their interface types (so I don't have to keep called Resolve on the IoC container each time I want a repository in my controll...

How do I use Unity to inject dependancies into ValidationFilters?

I know how to inject dependencies into Action Filters, but I cannot figure out how to do the same with Validation Filters. Is there the equivalent of an ActionInvoker I can tap into? ...

Asp.net Mvc - Kigg: Maintain User object in HttpContext.Items between requests.

first I want to say that I hope this doesn't look like I am lazy but I have some trouble understanding a piece of code from the following project. http://kigg.codeplex.com/ I was going through the source code and I noticed something that would be usefull for my own little project I am making. In their BaseController they have the follo...

When to use MEF

I tried Unity and MEF and plain old new. And I am a bit confused as to when exactly you need to use any of these "patterns". Why would I choose to use MEF or Unity if using new is simpler and satisfies my needs. In other words, what needs justify the use of MEF or Unity? ...

PerThreadLifetimeManager in Unity

Hi, In the Unity PerThreadLifetimeManager documentation, I read that: "This lifetime manager does not dispose the instances it holds". Ref.: http://msdn.microsoft.com/en-us/library/ff647854.aspx So, if I am using a ThreadPool, does it mean that objects resolved using Unity on a Thread of the ThreadPool will not get disposed at the end...

Unity IoC and MVC modelbinding

Is it ok to have a static field in my controller for my modelbinder to call ? Eg. public class AuctionItemsController : Controller { private IRepository<IAuctionItem> GenericAuctionItemRepository; private IAuctionItemRepository AuctionItemRepository; public AuctionItemsController(IRepository<IAuctionItem> genericAuctionIt...

Can Unity be made to not throw SynchronizationLockException all the time?

The Unity dependency injection container has what seems to be a widely known issue where the SynchronizedLifetimeManager will often cause the Monitor.Exit method to throw a SynchronizationLockException which is then caught and ignored. This is a problem for me because I like to debug with Visual Studio set to break on any thrown exceptio...

Unity doesn't work

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, par...

Question about mixing MEF and Unity

I'm finally diving into Unity head first, and have run into my first real problem. I've been gradually changing some things in my app from being MEF-resolved to Unity-resolved. Everything went fine on the application side, but then I realized that my plugins were not being loaded. I started to look into this issue, and I believe it's ...

Unity 2.0. How to throw ResolutionFailedException

Hello, I have my app, using functionality that is based on unity application block. Sometimes I need to throw ResolutionFailedException manually. In v1.2 constructor of ResolutionFailedException had three parameters - typerequested, namerequested and exception. In v2.0 fourth parameter was added - buildercontext. I'm not creating it manu...

ASP.Net Layered Application and the Unity Framework

Currently my layered ASP.Net application is structured like this: Entity Layer (data model classes auto-created using T4 against my Entity Data Model (edmx) in the data layer) Data Layer (Containing the edmx) Business Layer UI Layer The entity layer is referenced in all layers. My UI layer uses MVC 2. I'd like to implement the uni...

How to inject dependencies into a custom UserNamePasswordValidator in WCF?

I'm using a UserNamePasswordValidator in WCF along with Unity for my dependency injection, but since WCF creates the instance of the UserNamePasswordValidator, I cannot inject my container into the class. So how would one go about this? The simplest solution I can think of is to create a static proxy/wrapper class around a static insta...

How to get Code Coverage working on a VS 2010 project?

When I turn on Code Coverage in my test settings, on a project that references the Unity DI container I get the following error: Cannot initialize the ASP.NET project '{Project Name}'. The event log specifies the following reason: Could not load file or assembly 'Microsoft.Practices.Unity, Version=2.0.414.0, Culture=neutr...

Unity 2 - Why has the BuildUp method changed?

I am starting to use Unity 2 , having happily used earlier versions. I notice that the IUnityContainer.BuildUP(object obj) method has been removed. Why has this happened? ...

RegisterType with an interface in UnityContainer

I'm using UnityContainer, and I want to register an interface not with a type, but with another interface. Unfortunately, I'm unable to do it cleanly.. I have several common interfaces, which are united in one interface, and I need to register them in the container. The code is like the following: interface IDeviceImporter { void I...

How to indicate which implementation of an interface to return, based on some flag/argument?

In a distributed application that has multiple databases that support it, we're looking for better ways to handle the creation of the database connections. For example, suppose your system has three database behind it: Business Data (orders, products, categories, etc) Metadata (data about the structure of the business data) User Data (...

Unity and Object Creation

I am using unity as my IoC container. I am trying to implement a type of IProviderRepository. The concrete implementation has a constructor that accepts a type of IRepository. When I remove the constructor parameter from the concrete implementation everything works fine. I am sure the container is wired correctly. When I try to crea...

Recursion in Unity and Dispose pattern implementation

My class is inherited from UnityContainer (from Unity 2.0), here is source code: public class UnityManager : UnityContainer { private UnityManager() { _context = new MyDataClassesDataContext(); // ... } protected override void Dispose(bool disposing) { ...