/// <summary> /// Registers all types of the specified Assembly, as Singleton, on the specified container. /// </summary> /// <param name="container">The container.</param> /// <param name="serviceType">Type of the service.</param> /// <param name="assembly">The assembly.</param> /// <param name="filter">The filter.</param> /// <returns>The container.</returns> public static SimpleContainer AllTypesOfAsSingleton(this SimpleContainer container, Type serviceType, Assembly assembly, Func <Type, bool> filter = null) { if (null == filter) { filter = type => true; } var types = from type in assembly.GetTypes() where serviceType.IsAssignableFrom(type) && !type.IsAbstract && !type.IsInterface && filter(type) select type; foreach (var type in types) { container.RegisterSingleton(serviceType, null, type); } return(container); }
/// <summary> /// Registers the specified object and service as Singleton, on the specified container. /// </summary> /// <typeparam name="TService">The type of the service.</typeparam> /// <typeparam name="TImplementation">The type of the implementation.</typeparam> /// <param name="container">The container.</param> /// <returns>The container.</returns> public static SimpleContainer Singleton <TService, TImplementation>(this SimpleContainer container) where TImplementation : TService { container.RegisterSingleton(typeof(TService), null, typeof(TImplementation)); return(container); }
/// <summary> /// Registers the specified object as Singleton, on the specified container. /// </summary> /// <typeparam name="TImplementation">The type of the implementation.</typeparam> /// <param name="container">The container.</param> /// <returns>The container.</returns> public static SimpleContainer Singleton <TImplementation>(this SimpleContainer container) { container.RegisterSingleton(typeof(TImplementation), null, typeof(TImplementation)); return(container); }