Exemple #1
0
        /// <summary>
        /// 注册容器
        /// </summary>
        private void RegisterAndResolverIoc()
        {
            var builder = new ContainerBuilder();

            builder.RegisterApiControllers(Assembly.GetExecutingAssembly());
            TypeFinder typeFinder = new TypeFinder();

            foreach (var item in typeFinder.Assemblies)
            {
                DependencyConfig.RegisterDependency(item, builder);
            }

            var container = builder.Build();

            DependencyResolver.SetResolver(container);
            GlobalConfiguration.Configuration.DependencyResolver = new AutofacWebApiDependencyResolver(container);
        }
Exemple #2
0
        /// <summary>
        /// 注册容器
        /// </summary>
        private void RegisterAndResolverIoc()
        {
            ContainerBuilder builder = new ContainerBuilder();

            //注册mvc容器的实现
            builder.RegisterControllers(Assembly.GetExecutingAssembly());//没有为该对象定义无参数的构造函数。(mvc控制器构造函数注入)

            TypeFinder typeFinder = new TypeFinder();

            foreach (var item in typeFinder.Assemblies)
            {
                DependencyConfig.RegisterDependency(item, builder);
            }

            var container = builder.Build();

            Framework.Mayiboy.Ioc.DependencyResolver.SetResolver(container);
            System.Web.Mvc.DependencyResolver.SetResolver(new AutofacDependencyResolver(container));
        }