unity

Cascading Resolution in Unity

Suppose I have two types, TypeA and TypeB, that I want to register with Unity. TypeB depends on TypeA so I want to inject TypeA into type B through constructor injection. So I would like to write something like the following and have Unity be smart enough to cascade the resolution for me: _container.RegisterType<ITypeA, TypeA>(); _con...

Unity interception and constructors

I'd like to use interception with Unity, here is my code : UnityContainer container = new UnityContainer(); container.AddNewExtension<Interception>(); container.RegisterType<T, T>(); container.Configure<Interception>().SetDefaultInterceptorFor<T>(new VirtualMethodInterceptor()); return container.Resolve<T>(); If T is a class with a co...

Unity/Spring or System.Configuration for configuration?

If you are already using Unity as a part of your project, is there any sense in bothering with writing traditional configuration classes? Doing so seems like it's extra work, but the positives would be more domain specific XML tag names and more concise XML. But then the question becomes when you draw the line between the two and consi...

How do you reconcile IDisposable and IoC?

I'm finally wrapping my head around IoC and DI in C#, and am struggling with some of the edges. I'm using the Unity container, but I think this question applies more broadly. Using an IoC container to dispense instances that implement IDisposable freaks me out! How are you supposed to know if you should Dispose()? The instance migh...

Game development on iPhone using Unity engine

Hi, Im very new to game development on the iPhone... And I have a question: If I was to unity, how would that work... Would I use objective-c in unity? or is all of it like just click it, and add properties, no code (that may be a stupid question, but im just wondering) And once your done with the unity app, does it automaticly complil...

Unity [dependency] injection and Inheritance

Hi, My question is as follows: I have a base controller (ASP.Net MVC controller) called ApplicationController, and I want all my controller to inherit from it. this base controller has a ILogger property, marked with a [Dependency] attribute. (yes, I know I should use constructor injection, I'm just curious about this attribute). I cre...

Unity & Entlib on Azure

Hi Guys, I am using unity & entlib for logging and caching in my Azure webapp - I have strange problem in that the web browser takes a very long time to load. It seems there is a conflict with the web.config file but unsure what to do ? I need to wait 1-2 mins for the start page to display, sometimes it doesn't display at all - clean...

Unity Interception and Exceptions

hi there, i´m currently dealing with an issue where i have a lot of iterfaces and their implementations all created with unity. those classes contain some methods that throw exceptions on a regular base and i wanted to create a dynamic proxy around those classes so i can catch all exceptions occured in methods do handle them somewhere e...

In CAL, how can I get a reference to a module instance?

Hello, I have this application using CAL. All the modules derive from a special class, ModuleBase, which has an abstract method, say ApplySecurity implemented in each one of them. OK I load the modules in the bootstrapper, and after i call bootstrapper.Run(), i want to access all the modules that were loaded and call this ApplySecuri...

Best Practice - Share UnityContainer across Tiers in Asp.net MVC?

I have a UnityContainer that gets it's configuration information at runtime in the global.asax file of an MVC web app. I also have services in another assembly that need access to this container so that they can perform resolutions manually. How can I best share the two? I don't want to have a reference between my Data assembly and MV...

MVC/Unity - How to inject dependencies into custom FilterAttributes?

I Have a custom HandleErrorAttribute that extends FilterAttribute. How can I have Unity inject dependencies into this attribute at the same time that it injects the controller's dependencies itself? ...

Unity Newbie Question

I'm attempting to use Unity for the first time and I think I might have bitten off more than I can chew. We have a n-tier application that has a base library with several abstract types and then several business scenario specific libraries on top of it w/ concrete types. For ex: The abstract type lead has two implementations, one in a Ne...

Unity configure by convention

Is it possible to configure the Unity Dependency Injection framework to resolve by convention. So in other words if I have an ICustomerRepository when it tries to resolve this it will first look to see if there are any registered types and if not will then by convention try and resolve CustomerRepository class. This would save a lot of ...

Ninject vs Unity for DI

We are using ASP.net MVC. Which of these is the best DI framework Ninject or Unity and why? ...

How to hide the real IoC container library?

Hi, I want to isolate all my code from the IoC container library that I have chosen (Unity). To do so, I created an IContainer interface that exposes Register() and Resolve(). I created a class called UnityContainerAdapter that implements IContainer and that wraps the real container. So only the assembly where UnityContainerAdapter is ...

What corresponds to the Unity 'registration name' in the unity configuration section?

When registering and resolving types in a Unity Container using code you can use 'Registration Names' to disambiguate your references that derive from an interface or base class hierarchy. The 'registration name' text would be provided as a parameter to the register and resolve methods: myContainer.RegisterType<IMyService, CustomerSer...

Programatic property injection with Microsoft Unity

I use contructor injection in my solution, but this one class has a property that i do not want to pass in the constructor where i have the invariant dependencies. Let's say i got an ILogger and it has a FileName property i want to set, while still having it set the dependancies in the contructor. How do i go about registering the type,...

Unity Container - Passing in T dynamically to the Resolve method

I've created an ISearchable interface that I've Typed so that I can retrieve an IEnumerable of T for the results. I have a number of services that implement ISearchable for different domain objects ... Container.RegisterType<ISearchable<Animal>, AnimalService>(); Container.RegisterType<ISearchable<Fish>, FishService>(); I...

Singleton Per Call Context (Web Request) in Unity

Hi, A few days ago I had this issue with ASP.Net threading. I wanted to have a singleton object per web request. I actually need this for my unit of work. I wanted to instantiate a unit of work per web request so that identity map is valid through out the request. This way I could use an IoC to inject my own IUnitOfWork to my repository...

Can someone explain the magic going on in Prism's resolve<> method?

I've got a CustomersModule.cs with the following Initialize() method: public void Initialize() { container.RegisterType<ICustomersRepository, CustomersRepository>(new ContainerControlledLifetimeManager()); CustomersPresenter customersPresenter = this.container.Resolve<CustomersPresenter>(); } The class I resolve from the cont...