If you want to register several types with the same registration, you will need a singleton registration object for your implementation type IocImpl .
Then you need to use AddRegistration to add this registration for different services: IocInterface1 , IocInterface2 , etc.:
var _container = new Container(); var registration = Lifestyle.Singleton.CreateRegistration<IocImpl, IocImpl>(_container); _container.AddRegistration(typeof(IocImpl), registration); _container.AddRegistration(typeof(IocInterface1), registration); _container.AddRegistration(typeof(IocInterface2), registration);
as described in the documentation: Register multiple interfaces with the same implementation
Alternatively, you can also do the mapping using delegates:
_container.RegisterSingle<IocImpl>(); _container.RegisterSingle<IocInterface1>(() => container.GetInstance<IocImpl>()); _container.RegisterSingle<IocInterface2>(() => container.GetInstance<IocImpl>());
In most cases, both examples are functionally equivalent, but the former is preferable.
nemesv
source share