I'm new to the all DI pattern idea and i have some basic design doubts. im using Unity application blocks 2.0 as my DI framwork.
To the questions :
well one solution possible is to create another level of abstraction for each actual device like
public interface IActualDevice : IDevice { }
public class ActualDevice : IActualDevice { }
public class SimulatedActualDevice : IActualDevice { }
public class OtherAcualDevice : IOtherAcualDevice { }
then it would be possible to create such kind of mapping :
container.RegisterType<IActualDevice, ActualDevice>()
or if the HW is missing :
container.RegisterType<IActualDevice, SimulatedActualDevice>()
so what do you say is this good design ?
What about glue, what about the event subscription between objects ?
don't you think it is missing or better am i missing some Unity feature that supports it.
There's no need to introduce Marker Interfaces to make your DI Container work - that would be a Leaky Abstraction.
With Unity, you can configure each Listener with its own IDevice implementation like this:
container.RegisterType<IDevice, ActualDevice>("actual");
container.RegisterType<IDevice, OtherActualDevice>("otherActual");
container.RegisterType<IListener, Listener1>("listener1",
new InjectionConstructor(
new ResolvedParameter<IDevice>("actual")));
container.RegisterType<IListener, Listener2>("listener2",
new InjectionConstructor(
new ResolvedParameter<IDevice>("otherActual")));
You can now resolve the listeners like this:
var listener1 = container.Resolve<IListener>("listener1");
var listener2 = container.Resolve<IListener>("listener2");
In general, the core patterns of DI are Constructor Injection and Abstract Factory. Most other things follow from these two. See this answer for more DI patterns and principles.