/// <summary> /// Registers named mappings of /// T -> T /// and /// all implemented interfaces of T -> T /// for N. /// </summary> public void RegisterMapping <N, T>(MapInstantiation instantiation) { var manager = GetManagerFor(instantiation); var tfor = typeof(N); var destinationType = typeof(T); switch (instantiation) { case MapInstantiation.PerClass: case MapInstantiation.PerInstance: Container.RegisterType <T>(tfor.FullName, manager()); foreach (var destinationInterface in destinationType.GetInterfaces()) { Container.RegisterType(destinationInterface, destinationType, tfor.FullName, manager()); } return; case MapInstantiation.PerInstanceAndItsChilds: FRegistrations[tfor] = new Registration(destinationType, destinationType, manager); foreach (var destinationInterface in destinationType.GetInterfaces()) { FRegistrations[tfor] = new Registration(destinationInterface, destinationType, manager); } return; default: throw new Exception("mapping type not implemented"); } }
public void RegisterDefaultMapping(Type fromType, Type toType, MapInstantiation instantiation) { var manager = GetManagerFor(instantiation); switch (instantiation) { case MapInstantiation.PerClass: case MapInstantiation.PerInstance: Container.RegisterType(fromType, toType, manager()); return; default: throw new Exception("mapping type not implemented"); } }
protected Func <LifetimeManager> GetManagerFor(MapInstantiation instantiation) { switch (instantiation) { case MapInstantiation.PerClass: case MapInstantiation.PerInstanceAndItsChilds: return(() => new ContainerControlledLifetimeManager()); case MapInstantiation.PerInstance: return(() => new HierarchicalLifetimeManager()); default: return(null); } }
/// <summary> /// Registers named mapping of /// TFrom -> TTo /// for N. /// </summary> public void RegisterMapping(Type forType, Type fromType, Type toType, MapInstantiation instantiation) { var manager = GetManagerFor(instantiation); switch (instantiation) { case MapInstantiation.PerClass: case MapInstantiation.PerInstance: Container.RegisterType(fromType, toType, forType.FullName, manager()); return; case MapInstantiation.PerInstanceAndItsChilds: FRegistrations[forType] = new Registration(fromType, toType, manager); return; default: throw new Exception("mapping type not implemented"); } }
/// <summary> /// Registers default mapping of /// TFrom -> TTo. /// </summary> public void RegisterDefaultMapping <TFrom, TTo>(MapInstantiation instantiation) where TTo : TFrom { RegisterDefaultMapping(typeof(TFrom), typeof(TTo), instantiation); }