Пример #1
0
        public static IDependencyContainer RegisterRepository(this IDependencyContainer container, Action <DbContextOptionsBuilder> optionsAction)
        {
            var options = new DbContextOptionsBuilder <CNCLibContext>();

            optionsAction(options);

            container.RegisterInstance <DbContextOptions <CNCLibContext> >(options.Options);
            container.RegisterTypeScoped <CNCLibContext, CNCLibContext>();
            container.RegisterTypeScoped <IUnitOfWork, UnitOfWork <CNCLibContext> >();

            container.RegisterTypesIncludingInternals(DependencyLivetime.Transient, typeof(Repository.MachineRepository).Assembly);
            return(container);
        }
Пример #2
0
        public static IDependencyContainer RegisterTypesByNameScoped(this IDependencyContainer container, Func <string, bool> checkname, params Assembly[] assemblies)
        {
            foreach (var assembly in assemblies)
            {
                foreach (var type in assembly.GetTypes().Where(t => t.IsClass && !t.IsAbstract))
                {
                    if (checkname(type.Name))
                    {
                        container.RegisterTypeScoped(type, type);
                    }
                }
            }

            return(container);
        }
Пример #3
0
        /// <summary>
        /// Registers public and internal types of the given assemblies with the unity container. This is necessary
        /// to workaround the internalsvisibleto hacks in the code base.
        /// </summary>
        /// <param name="container"></param>
        /// <param name="assemblies">List of assemblies in which all types should be registered with their interfaces.
        /// This includes internal types. </param>
        /// <returns>This instance.</returns>
        public static IDependencyContainer RegisterTypesIncludingInternalsScoped(this IDependencyContainer container, params Assembly[] assemblies)
        {
            foreach (var assembly in assemblies)
            {
                foreach (var type in assembly.GetTypes().Where(t => t.IsClass && !t.IsAbstract))
                {
                    string interfacename = "I" + type.Name;
                    var    interfacetype = type.GetInterface(interfacename);
                    if (interfacetype != null)
                    {
                        container.RegisterTypeScoped(interfacetype, type);
                    }
                }
            }

            return(container);
        }
Пример #4
0
 /// <summary>
 /// Registers a type for the given interface.
 /// </summary>
 /// <returns>This instance.</returns>
 public static IDependencyContainer RegisterTypeScoped <TType>(this IDependencyContainer container)
 {
     container.RegisterTypeScoped(typeof(TType), typeof(TType));
     return(container);
 }
Пример #5
0
 /// <summary>
 /// Registers a type for the given interface.
 /// </summary>
 /// <typeparam name="TInterface">Interface that can be later resolved.</typeparam>
 /// <typeparam name="TType">Type that implements interface. On Resolve&lt;TInterface&gt;() calls a new instance is returned every time.</typeparam>
 /// <returns>This instance.</returns>
 public static IDependencyContainer RegisterTypeScoped <TInterface, TType>(this IDependencyContainer container) where TType : TInterface
 {
     container.RegisterTypeScoped(typeof(TInterface), typeof(TType));
     return(container);
 }