/// <summary> /// Adds the given type to the containers registry. /// </summary> /// <typeparam name="T">The type to register</typeparam> public void Register <T>() where T : class { var type = typeof(T); var typeData = TypeData.Create(type); this.Register(null, type, typeData); }
/// <summary> /// Adds the given instance to the containers registry. This instance will be handled as a singleton. /// Multiple implementations of the same type are distinguished through a given key. /// </summary> /// <typeparam name="T">The type to register</typeparam> /// <param name="instance">The instance that is going to be registered in the container.</param> /// <param name="key">Optional.The key to distinguish between implementations of the same interface.</param> public void RegisterSingleton <T>(T instance, string key = null) where T : class { var type = typeof(T); var typeData = TypeData.Create(type, true, instance); this.Register(null, type, typeData, key); }
/// <summary> /// Adds the given interface to the containers registry and links it with an implementation of this interface. /// The instance of this type will be handled as a singleton. /// Multiple implementations of the same type are distinguished through a given key. /// </summary> /// <typeparam name="TInterface">The type of the interface.</typeparam> /// <typeparam name="TClass">The type of the class.</typeparam> /// <param name="key">Optional.The key to distinguish between implementations of the same interface.</param> public void RegisterSingleton <TInterface, TClass>(string key = null) where TClass : class, TInterface { var typeInterface = typeof(TInterface); var type = typeof(TClass); var typeData = TypeData.Create(type, true); this.Register(typeInterface, type, typeData, key); }
private TypeData GetTypeData(Type type) { if (!this.typeDatas.ContainsKey(type)) { var typeData = TypeData.Create(type); this.Register(null, type, typeData); } return(this.typeDatas[type]); }