Ejemplo n.º 1
0
        /// <summary>
        /// 为测试环境注册依赖
        /// </summary>
        /// <param name="modules">依赖配置</param>
        public static void RegisterTest(params IModule[] modules)
        {
            var path       = Sys.GetPhysicalPath(AppDomain.CurrentDomain.BaseDirectory);
            var assemblies = Reflection.GetAssemblies(path);

            Container.Init(builder => RegisterTypes(assemblies, builder), modules);
        }
Ejemplo n.º 2
0
        /// <summary>
        /// 为Mvc注册依赖
        /// </summary>
        /// <param name="mvcAssembly">mvc项目所在的程序集</param>
        /// <param name="modules">依赖配置</param>
        public static IServiceProvider RegisterNetCore(IServiceCollection services, params IModule[] modules)
        {
            var assemblies       = AppDomain.CurrentDomain.GetAssemblies();
            var containerBuilder = Container.CreateBuilder(builder => RegisterTypes(assemblies, builder), modules);

            containerBuilder.Populate(services);
            var container = containerBuilder.Build();

            return(new AutofacServiceProvider(container));
        }
Ejemplo n.º 3
0
 /// <summary>
 /// 创建实例
 /// </summary>
 /// <param name="type">对象类型</param>
 public static object Create(Type type)
 {
     return(Container.Create(type));
 }
Ejemplo n.º 4
0
 /// <summary>
 /// 创建实例
 /// </summary>
 /// <typeparam name="T">实例类型</typeparam>
 public static T Create <T>()
 {
     return(Container.Create <T>());
 }
Ejemplo n.º 5
0
        /// <summary>
        /// 为Mvc注册依赖
        /// </summary>
        /// <param name="mvcAssembly">mvc项目所在的程序集</param>
        /// <param name="modules">依赖配置</param>
        public static void RegisterMvc(Assembly mvcAssembly, params IModule[] modules)
        {
            var assemblies = AppDomain.CurrentDomain.GetAssemblies();

            Container.RegisterMvc(mvcAssembly, builder => RegisterTypes(assemblies, builder), modules);
        }