Inheritance: IDependencyResolver
Ejemplo n.º 1
0
        protected void Application_Start()
        {
            AreaRegistration.RegisterAllAreas();

            RegisterGlobalFilters(GlobalFilters.Filters);
            RegisterRoutes(RouteTable.Routes);
            
            var container = new UnityContainer();
            container.RegisterType<IStoreService, StoreService>();
            container.RegisterType<IController, StoreController>("Store");

            var factory = new UnityControllerFactory(container);
            ControllerBuilder.Current.SetControllerFactory(factory);

            IDependencyResolver resolver = DependencyResolver.Current;

            // You could implement another IMessageService, maybe a dynamic one
            container.RegisterInstance<IMessageService>(new MessageService { 
                Message = "You are welcome to our Web Camps Training Kit!",
                ImageUrl = "/Content/Images/logo-webcamps.png"    
            });
            container.RegisterType<IViewPageActivator, CustomViewPageActivator>(new InjectionConstructor(container));

            IDependencyResolver newResolver = new UnityDependencyResolver(container, resolver);

            DependencyResolver.SetResolver(newResolver);
        }
        public static void Initialise()
        {
            var container = BuildUnityContainer();

            DependencyResolver.SetResolver(new Unity.Mvc3.UnityDependencyResolver(container));

            IDependencyResolver resolver = DependencyResolver.Current;

            IDependencyResolver newResolver = new Factories.UnityDependencyResolver(container, resolver);

            DependencyResolver.SetResolver(newResolver);
        }
        public static void Initialise()
        {
            var container = BuildUnityContainer();

            DependencyResolver.SetResolver(new Unity.Mvc3.UnityDependencyResolver(container));

            IDependencyResolver resolver = DependencyResolver.Current;

            IDependencyResolver newResolver = new Factories.UnityDependencyResolver(container, resolver);

            DependencyResolver.SetResolver(newResolver);
        }
        protected void Application_Start()
        {
            AreaRegistration.RegisterAllAreas();

            RegisterGlobalFilters(GlobalFilters.Filters);
            RegisterRoutes(RouteTable.Routes);

            var container = new UnityContainer();
            //Custom Container Locator, because one is not enough...
            ContainerLocator.Container = container;

            //Aspects enabled
            container.AddNewExtension<Interception>();

            //Controllers
            var factory = new UnityControllerFactory(container);
            ControllerBuilder.Current.SetControllerFactory(factory);

            //Log config
            var assembly = Assembly.GetExecutingAssembly();
            const string resourceName = "MvcMusicStore.Config.music_store-log4net.xml";
            using (Stream stream = assembly.GetManifestResourceStream(resourceName))
            {
                if (stream != null)
                {
                    XmlConfigurator.Configure(stream);
                }
            }

            container.RegisterType<ILogger, Log4NetLoggerAdapter>(new PerResolveLifetimeManager(),
                                                                   new InjectionConstructor(MethodBase.GetCurrentMethod()));
            //Wake up the logger
            Logger = container.Resolve<ILogger>();
            Logger.Info("Stuff Initialized!");

            IDependencyResolver resolver = DependencyResolver.Current;
            IDependencyResolver newResolver = new UnityDependencyResolver(container, resolver);
            DependencyResolver.SetResolver(newResolver);

            //Register Types - add the instrumentation interceptor
            container.RegisterType<IStoreService, StoreService>(new ContainerControlledLifetimeManager(),
                                                                         new Interceptor<InterfaceInterceptor>(),
                                                                         new InterceptionBehavior<InstrumentationInterceptor>());
            container.RegisterType<IController, StoreController>("Store");

            container.RegisterType<IViewPageActivator, CustomViewPageActivator>(new InjectionConstructor(container));

            container.RegisterInstance<IFilterProvider>("FilterProvider", new FilterProvider(container));
            container.RegisterInstance<IActionFilter>("TraceActionFilter", new TraceActionFilter());
        }