/// <summary>
 /// Bind type
 /// </summary>
 /// <param name="bindingTypes"></param>
 internal void Bind(TypesBinder bindingTypes)
 {
     if (bindingTypes.ImplementType != null)
     {
         _addBindingWrapper.Add(
             bindingTypes.Services,
             bindingTypes.SingleType,
             bindingTypes.ImplementType,
             bindingTypes.LifeTimeOptions,
             bindingTypes.IsPropertiesAutoWired);
     }
     else if (bindingTypes.IsImplementByInterface)
     {
         _implementByInterfaceHelper.Add(
             bindingTypes.Services,
             bindingTypes.SingleType,
             bindingTypes.LifeTimeOptions,
             bindingTypes.IsPropertiesAutoWired);
     }
     else
     {
         _addBindingWrapper.Add(
             bindingTypes.Services,
             bindingTypes.SingleType,
             null,
             bindingTypes.LifeTimeOptions,
             bindingTypes.IsPropertiesAutoWired);
     }
 }
        /// <summary>
        /// Bind range types
        /// </summary>
        /// <param name="bindingTypes"></param>
        /// <param name="types"></param>
        internal void Bind(TypesBinder bindingTypes, IEnumerable <Type> types)
        {
            types = (Type[])types;

            if (types == null || !types.Any())
            {
                return;
            }
            foreach (var type in types)
            {
                if (bindingTypes.IsImplementByInterface)
                {
                    _implementByInterfaceHelper.Add(
                        bindingTypes.Services,
                        type,
                        bindingTypes.LifeTimeOptions,
                        bindingTypes.IsPropertiesAutoWired);
                }
                else
                {
                    _addBindingWrapper.Add(
                        bindingTypes.Services,
                        type,
                        null,
                        bindingTypes.LifeTimeOptions,
                        bindingTypes.IsPropertiesAutoWired);
                }
            }
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Bind assembly types
        /// </summary>
        /// <param name="service">Service collection</param>
        /// <param name="assembly">Assembly</param>
        /// <returns></returns>
        public static TypesBinder RegisterAssemblyTypes(this IServiceCollection service, Assembly assembly)
        {
            var bindingTypes = new TypesBinder
            {
                Services = service,
                Assembly = assembly
            };

            return(bindingTypes);
        }
        /// <summary>
        /// Bind single type as service with options
        /// </summary>
        /// <typeparam name="T">Type</typeparam>
        /// <param name="services">Service collection</param>
        /// <returns></returns>
        public static TypesBinder RegisterType <T>(this IServiceCollection services)
        {
            var bindingTypes = new TypesBinder
            {
                Services = services,

                SingleType = typeof(T)
            };

            return(bindingTypes);
        }
        /// <summary>
        /// Bind types as services by name
        /// </summary>
        /// <param name="services">Service collection</param>
        /// <param name="assembly">Assembly of types</param>
        /// <param name="nameComparer">Type name comparer for bind</param>
        /// <returns></returns>
        public static TypesBinder RegisterAssemblyTypesByName(this IServiceCollection services,
                                                              Assembly assembly,
                                                              Func <string, bool> nameComparer)
        {
            var bindingTypes = new TypesBinder
            {
                Assembly     = assembly,
                Services     = services,
                NameComparer = nameComparer
            };

            return(bindingTypes);
        }
Ejemplo n.º 6
0
        /// <summary>
        /// bind two types with options
        /// </summary>
        /// <typeparam name="T">Interface or base type</typeparam>
        /// <typeparam name="TImplemented"></typeparam>
        /// <param name="services">Implementing type</param>
        /// <returns></returns>
        public static TypesBinder RegisterTypes <T, TImplemented>(this IServiceCollection services)
        {
            var bindingTypes = new TypesBinder
            {
                Services = services,

                SingleType = typeof(T),

                ImplementType = typeof(TImplemented)
            };

            return(bindingTypes);
        }