Exemplo n.º 1
0
 public UnityRegister(IUnityContainer container)
 {
     _container = container;
     PublicTypes.Each(p =>
     {
         if (p.IsClass && !p.IsAbstract && !p.IsInterface && !p.IsGenericType)
         {
             if ((KnownTypes.DependencyType.IsAssignableFrom(p) ||
                  KnownTypes.EntityType.IsAssignableFrom(p)) && !KnownTypes.FreeDependencyType.IsAssignableFrom(p))
             {
                 if (KnownTypes.EntityType.IsAssignableFrom(p))
                 {
                     _container.RegisterType(p, GetLifetimeManager(p));
                 }
                 else
                 {
                     foreach (var inter in p.GetInterfaces())
                     {
                         _container.RegisterType(inter, p, GetLifetimeManager(p));
                         _container.RegisterType(inter, p, inter.Name + p.FullName, GetLifetimeManager(p));
                     }
                 }
             }
         }
     });
 }
Exemplo n.º 2
0
 public UnityRegister(IUnityContainer container)
 {
     _container = container;
     PublicTypes.Each(p =>
     {
         if (p != null && p.IsClass && !p.IsAbstract && !p.IsInterface && !p.IsGenericType)
         {
             if ((KnownTypes.DependencyType.IsAssignableFrom(p) ||
                  KnownTypes.EntityType.IsAssignableFrom(p)) && !KnownTypes.FreeDependencyType.IsAssignableFrom(p))
             {
                 if (KnownTypes.EntityType.IsAssignableFrom(p))
                 {
                     _container.RegisterType(p, GetLifetimeManager(p));
                 }
                 else
                 {
                     foreach (var inter in p.GetInterfaces())
                     {
                         _container.RegisterType(inter, p, GetLifetimeManager(p));
                         _container.RegisterType(inter, p, inter.Name + p.FullName, GetLifetimeManager(p));
                     }
                     if (p.BaseType != null && p.BaseType.IsAbstract)
                     {
                         RegistBaseType(p, p.BaseType);
                     }
                 }
             }
             if (KnownTypes.ModuleType.IsAssignableFrom(p))
             {
                 ((IModule)Activator.CreateInstance(p)).Load(new UnityContainerAdapter(container));
             }
         }
     });
 }
Exemplo n.º 3
0
        public AutofacRegister(ContainerBuilder builder, Type controllerType)
        {
            PublicTypes.Each(p =>
            {
                if (p != null && p.IsClass && !p.IsAbstract && !p.IsInterface && !p.IsGenericType)
                {
                    if ((KnownTypes.DependencyType.IsAssignableFrom(p) ||
                         KnownTypes.EntityType.IsAssignableFrom(p)) && !KnownTypes.FreeDependencyType.IsAssignableFrom(p))
                    {
                        MakeLifeTime(
                            KnownTypes.EntityType.IsAssignableFrom(p)
                                ? builder.RegisterType(p).AsSelf()
                                : builder.RegisterType(p).As(p.GetInterfaces()), p);

                        if (p.BaseType != null && p.BaseType.IsAbstract)
                        {
                            RegistBaseType(builder, p, p.BaseType);
                        }
                    }
                    if (controllerType.IsAssignableFrom(p))
                    {//register controller
                        builder.RegisterType(p);
                    }
                    if (KnownTypes.ModuleType.IsAssignableFrom(p))
                    {
                        ((IModule)Activator.CreateInstance(p)).Load(new AutofacContainerAdapter(builder));
                    }
                }
            });
        }
Exemplo n.º 4
0
        protected void Application_Start()
        {
            ModelValidatorProviders.Providers.Clear();
            ModelValidatorProviders.Providers.Add(new EasyModelValidatorProvider());
            ModelMetadataProviders.Current = new EasyModelMetaDataProvider();
            //ModelBinderProviders.BinderProviders.Add(new EasyBinderProvider());

            AutofacContainerBuilder = new ContainerBuilder();
            AutofacContainerBuilder.RegisterType <FilterControllerFactory>().As <IControllerFactory>();
            AutofacContainerBuilder.RegisterType <EasyControllerActivator>().As <IControllerActivator>();
            AutofacContainerBuilder.RegisterType <HttpItemsValueProvider>().As <IHttpItemsValueProvider>().SingleInstance();
            AutofacContainerBuilder.RegisterType <ApplicationContext>().As <IApplicationContext>().InstancePerLifetimeScope();

            AutofacContainerBuilder.RegisterType <RequestLifetimeScopeProvider>().As <ILifetimeScopeProvider>().SingleInstance();
            //AutofacContainerBuilder.RegisterType<DataDictionaryService>().As<IDataDictionaryService>();
            //AutofacContainerBuilder.RegisterType<LanguageService>().As<ILanguageService>().SingleInstance();


            var controllerType = typeof(System.Web.Mvc.Controller);
            var moduleType     = typeof(IModule);

            PublicTypes.Each(t =>
            {
                if (t != null && !t.IsInterface && !t.IsAbstract && t.IsPublic && !t.IsGenericType)
                {
                    if (controllerType.IsAssignableFrom(t))
                    {//register controller
                        AutofacContainerBuilder.RegisterType(t);
                    }
                    if (moduleType.IsAssignableFrom(t))
                    {
                        ((IModule)Activator.CreateInstance(t)).Load(new AutofacContainerAdapter(AutofacContainerBuilder));
                    }
                }
            });

            System.Web.Mvc.DependencyResolver.SetResolver(new EasyDependencyResolver());

            Application_Starting();

            _lifetimeScopeProvider = new AutofacRegister(AutofacContainerBuilder).Regist(AutofacContainerBuilder.Build());

            TaskManager.ExcuteAll();

            Application_Started();
        }
Exemplo n.º 5
0
 public AutofacRegister(ContainerBuilder builder)
 {
     PublicTypes.Each(p =>
     {
         if (p.IsClass && !p.IsAbstract && !p.IsInterface && !p.IsGenericType)
         {
             if ((KnownTypes.DependencyType.IsAssignableFrom(p) ||
                  KnownTypes.EntityType.IsAssignableFrom(p)) && !KnownTypes.FreeDependencyType.IsAssignableFrom(p))
             {
                 MakeLifeTime(
                     KnownTypes.EntityType.IsAssignableFrom(p)
                         ? builder.RegisterType(p).AsSelf()
                         : builder.RegisterType(p).As(p.GetInterfaces()), p);
             }
         }
     });
 }
        protected void Application_Start()
        {
            ModelValidatorProviders.Providers.Clear();
            ModelValidatorProviders.Providers.Add(new EasyModelValidatorProvider());
            ModelMetadataProviders.Current = new EasyModelMetaDataProvider();
            //ModelBinderProviders.BinderProviders.Add(new EasyBinderProvider());

            Container = new UnityContainer();
            Container.RegisterType <IControllerFactory, FilterControllerFactory>();
            Container.RegisterType <IControllerActivator, EasyControllerActivator>();
            Container.RegisterType <IHttpItemsValueProvider, HttpItemsValueProvider>(new ContainerControlledLifetimeManager());
            Container.RegisterType <IApplicationContext, ApplicationContext>(new PerRequestLifetimeManager());

            //Container.RegisterType<IDataDictionaryService, DataDictionaryService>();
            //Container.RegisterType<ILanguageService, LanguageService>(new ContainerControlledLifetimeManager());
            var moduleType = typeof(IModule);

            PublicTypes.Each(t =>
            {
                if (t != null && !t.IsInterface && !t.IsAbstract && t.IsPublic && !t.IsGenericType)
                {
                    if (moduleType.IsAssignableFrom(t))
                    {
                        ((IModule)Activator.CreateInstance(t)).Load(new UnityContainerAdapter(Container));
                    }
                }
            });

            System.Web.Mvc.DependencyResolver.SetResolver(new EasyDependencyResolver());

            Application_Starting();

            new UnityRegister(Container).Regist();

            TaskManager.ExcuteAll();

            Application_Started();
        }