/// <summary>
        /// Registers all specified types in an assembly as singletong in the container.
        /// </summary>
        /// <typeparam name="TService">The type of the service.</typeparam>
        /// <param name="container">The container.</param>
        /// <param name="assembly">The assembly.</param>
        /// <param name="filter">The type filter.</param>
        /// <returns>The container.</returns>
        public static SimpleContainer AllTypesOf <TService>(this SimpleContainer container, Assembly assembly, Func <Type, bool> filter = null)
        {
            if (filter == null)
            {
                filter = type => true;
            }

#if WinRT
            var serviceInfo = typeof(TService).GetTypeInfo();
            var types       = from type in assembly.DefinedTypes
                              let info = type.GetTypeInfo()
                                         where serviceInfo.IsAssignableFrom(info) &&
                                         !info.IsAbstract &&
                                         !info.IsInterface &&
                                         filter(type)
                                         select type;
#else
            var serviceType = typeof(TService);
            var types       = from type in assembly.GetTypes()
                              where serviceType.IsAssignableFrom(type) &&
                              !type.IsAbstract &&
                              !type.IsInterface &&
                              filter(type)
                              select type;
#endif

            foreach (var type in types)
            {
                container.RegisterSingleton(typeof(TService), null, type);
            }

            return(container);
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Registers all specified types in an assembly as singletong in the container.
        /// </summary>
        /// <typeparam name="TService">The type of the service.</typeparam>
        /// <param name="container">The container.</param>
        /// <param name="assembly">The assembly.</param>
        /// <param name="filter">The type filter.</param>
        /// <returns>The container.</returns>
        public static SimpleContainer AllTypesOf <TService>(this SimpleContainer container, Assembly assembly, Func <Type, bool> filter = null)
        {
            if (filter == null)
            {
                filter = type => true;
            }

            var types = from type in assembly.GetTypes()
                        where typeof(TService).IsAssignableFrom(type) &&
                        !type.IsAbstract &&
                        !type.IsInterface &&
                        filter(type)
                        select type;

            foreach (var type in types)
            {
                container.RegisterSingleton(typeof(TService), null, type);
            }

            return(container);
        }
Ejemplo n.º 3
0
 /// <summary>
 /// Registers a singleton.
 /// </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);
 }
Ejemplo n.º 4
0
 /// <summary>
 /// Registers a singleton.
 /// </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);
 }