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); }
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); }
/// <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); }
/// <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); }
/// <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<TInterface>() 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); }