unity

Map singleton to Interface using unity framework (config file)

Hi, is there is anyway to map/register singleton, using the unity configuration file, and map it to an interface while the singleton doesn't expose any public constructor? Please advice, Thanks ...

Resolving a constructor with two arguments of the same interface?

Another developer and had this conversation today: Me: Dependency Injection is cool, lol. Dennis: What happens when I need an instance of the DoStuff class and the only constructor I have is DoStuff( ISomeInterface interface1, ISomeInterface interface2 ) where the concrete types are completely different? Me: ... We use Unity as our p...

Unreal engine 3 vs Id tech 3 vs Unity

I'm trying to decide which engine I should start using to try to start building a game in. I had chosen Unity, but upon hearing that Unreal engine 3 had just become kinda free to use, I found myself questioning my decision. Technically unreal is still the most expensive commercially, then Unity, then Id tech 3(free). But, it also coul...

Lifetime management in mvc turbine?

How can I manage the lifetime of my services in mvc turbine (using Unity)? I have an ISearchService implementation LuceneSearchService that takes an IConfigurationService and ILoggerService. Currently my searchservice registration looks like this: public class SearchServiceRegistration: IServiceRegistration { public void Registe...

Why is this instance initiated by Unity not a singleton?

in my asp.net-mvc application I have a statis MvcApplication that calls a static CreateContainer() method. In this method I create my unity ioc container: private static IUnityContainer CreateContainer() { var container = new UnityContainer(); container.RegisterType<IConfigurationService, ConfigFile>(); container.RegisterTy...

Microsoft's Unity and PowerShell

In a C# solution, I have multiple class libraries for the domain model, services, and repositories. I configured Unity in web.config of the main website project so that it knows what concrete objects to map to the services and repositories. For quick testing, though, I'd like to use PowerShell to load the assemblies and manipulate classe...

Unity IOC Static Factories

Is there a way via xml configuration to denote a static factory method on an object? ...

Dependency Injection Wireup Question

If there are 3 interfaces like the following public interface IWeapon { void Kill(); } public interface ISword:IWeapon { void Slice(); } public interface IShuriken: IWeapon { void Pierce(); } public class Ninja { public IWeapon Weapon {get;set;} public void BrutalKill() { /* warrior must pierce, pierce, pierce and then kill */ }...

Is there a pattern for initializing objects created via a DI container

I am trying to get Unity to manage the creation of my objects and I want to have some initialization parameters that are not known until run-time: At the moment the only way I could think of the way to do it is to have an Init method on the interface. interface IMyIntf { void Initialize(string runTimeParam); string RunTimeParam { g...

Setting the parameterless constructor as the injection constructor in container creation

I have a class with two ctors. One parameterless and one with parameters. Unity will by default take the gready approach and go for the last ctor. How can I define what ctor to use (I want to parameterless) without adding dependency on Unity within my classes? I think it is possible to do it in my container creation, but I don't know ho...

Can Castle.Windsor do automatic resolution of concrete types

We are evaluating IoC containers for C# projects, and both Unity and Castle.Windsor are standing out. One thing that I like about Unity (NInject and StructureMap also do this) is that types where it is obvious how to construct them do not have to be registered with the IoC Container. Is there way to do this in Castle.Windsor? Am I bein...

Resolving IEnumerable<T> with Unity

Can Unity automatically resolve IEnumerable<T>? Let's say I have a class with this constructor: public CoalescingParserSelector(IEnumerable<IParserBuilder> parserBuilders) and I configure individual IParserBuilder instances in the container: container.RegisterType<IParserSelector, CoalescingParserSelector>(); container.RegisterType<...

Caliburn passing parameters to Container Commands.

Hi, I have a command that is registered correctly in Unity but when I pass parameters to it, the parameter values seem to be null. I have the command defined in XAML as following (note that I tried with Message.triggers in XAML but this also sent nulls for the parameters). <ButtonControls:HeaderButton x:Name="SendEmailbtn" Hor...

Caliburn : How to get an async result back to viewmodel and then view

Hi, I have a ContainerCommand (which is registered in Unity) which calls a web service asynchronously. What I want is the result of the web service to be some how propagated back to the view model and then view. The app is written in Silverlight. How can I do this? JD. ...

Unity: Specify Dependency name during configuration

I have following snippet: static void Main(string[] args) { var container = new UnityContainer(); container.RegisterType<IConnection, SerialPortConnection>("SerialConnection"); container.RegisterType<IConnection, ParallelPortConnection>("ParallelConnection"); container.RegisterType<Device>("ParallelDevice"); containe...

Resolving wrapper classes in C# with the Unity IoC container

I want to use Unity resolve IService to two different implementations, to make use of a wrapper class, the equivalent of: IService service = new DispatcherService(new RealService(), Application.Current.Dispatcher); Where both DispatcherService and RealService implement the IService interface. I have a library containing some service...

Constructor Injection in C#/Unity?

I'm using C# with Microsoft's Unity framework. I'm not quite sure how to solve this problem. It probably has something to do with my lack of understanding DI with Unity. My problem can be summed up using the following example code: class Train(Person p) { ... } class Bus(Person p) { ... } class Person(string name) { ... } Person dad...

How to configure Unity to apply a "constant" string for a constructor parameter during RegisterType() ?

This is what my service contructor looks like: public Service(string path) and I'm configuring unity like this: IUnityContainer container = new UnityContainer(); container.RegisterType<IService, Service>(); which of course is not correct. The path parameter needs to be specified, and I would like this to be configurable from the Ap...

Unity to Structure Map

I am trying out the code from this post on Event Driven Architecture (very interesting by the way). His IOC container is Unity though and I would like to do this using Structure map. His code is: public class EventSubscriptions : ISubscriptionService { public static void Add<T>() { var consumerType = typeof(T); con...

Unity IOC Buildup vs Resolve?

I was wondering when do I use buildup and when do I use resolve, when using the Unity IOC. And when do I call teardown? Thanks ...