public void Register <Tinterface, Timplementation>() { var myInterface = typeof(Tinterface); var myType = typeof(Timplementation); if (!myInterface.IsInterface) { throw new ArgumentException("Left Type must be interface"); } if (!myInterface.IsAssignableFrom(myType)) { throw new ArgumentException("Right Type must be assignable from left Type"); } var myDefaultConstructor = myType.GetConstructor(Type.EmptyTypes); if (myDefaultConstructor == null) { _myTypes[myInterface] = new ConcreteTypeCreationModel { ConcreteType = myType }; } else { _myTypes[myInterface] = new ConcreteTypeCreationModel { DefaultConstructor = myDefaultConstructor }; } }
public void Register <T>(Func <object> objectFactoryFunction) { var myType = typeof(T); _myTypes[myType] = new ConcreteTypeCreationModel { CustomCreationFunction = objectFactoryFunction }; }
public void Register <T>() { var myType = typeof(T); var myDefaultConstructor = myType.GetConstructor(Type.EmptyTypes); if (myDefaultConstructor == null) { _myTypes[myType] = new ConcreteTypeCreationModel { ConcreteType = myType }; } else { _myTypes[myType] = new ConcreteTypeCreationModel { DefaultConstructor = myDefaultConstructor }; } }
public void Register <Tinterface, Timplementation>(Func <object> objectFactoryFunction) { var myInterface = typeof(Tinterface); var myType = typeof(Timplementation); if (!myInterface.IsInterface) { throw new ArgumentException("Left Type must be interface"); } if (!myInterface.IsAssignableFrom(myType)) { throw new ArgumentException("Right Type must be assignable from left Type"); } _myTypes[myInterface] = new ConcreteTypeCreationModel { CustomCreationFunction = objectFactoryFunction }; }