Выпуск загрузок Castle Windsor Installers из сборки - PullRequest
0 голосов
/ 22 декабря 2011

Это, наверное, глупый вопрос! Меня заставляют использовать Castle Windsor в качестве моего IOC, и у меня возникают некоторые проблемы с настройкой MVC. Вот что у меня есть.

global.asax

protected void Application_Start()
    {
        AreaRegistration.RegisterAllAreas();

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

    }
    private void RegisterCastle()
    {
        _container = new WindsorContainer();
        _container.Install(FromAssembly.InDirectory(new AssemblyFilter(HttpRuntime.BinDirectory)));
        ControllerBuilder.Current.SetControllerFactory(new WindsorControllerFactory(_container.Kernel));
    }

Фабрика контроллеров работает, но это все. У меня есть отдельный проект с моими установщиками, и я хотел бы, чтобы он загружал любые установщики из сборок в текущем веб-проекте (мне может понадобиться кое-что там, я знаю).

Классы в проекте DI, использующие IWindsorInstaller, вообще не загружаются. Я что-то упустил?

В Ninject мы могли бы использовать

 kernel.Load(AppDomain.CurrentDomain.GetAssemblies());

1 Ответ

0 голосов
/ 29 декабря 2011

Я закончил с использованием WebActivator в App_Start

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using Castle.Facilities.TypedFactory;
using Castle.MicroKernel;
using Castle.MicroKernel.Registration;
using Castle.Windsor;
using Castle.Windsor.Installer;
using DFW.Domain.Interfaces;
using UI.App_Start;
using UI.Windsor;

[assembly: WebActivator.PostApplicationStartMethod(typeof(Bootstrapper), "Wire")]
[assembly: WebActivator.ApplicationShutdownMethod(typeof(Bootstrapper), "DeWire")]

namespace UI.App_Start
{
    public class Bootstrapper
    {
        private static readonly IWindsorContainer Container = new WindsorContainer();
        public static void Wire()
        {
            //To be able to inject IEnumerable<T> ICollection<T> IList<T> T[] use this:
            //container.Kernel.Resolver.AddSubResolver(new CollectionResolver(container.Kernel, true));
            //Documentation http://docs.castleproject.org/Windsor.Resolvers.ashx

            //To support typed factories add this:
            Container.AddFacility<TypedFactoryFacility>();
            Container.Register(Component.For<IServiceFactory>().AsFactory().LifestyleTransient());
            //Documentation http://docs.castleproject.org/Windsor.Typed-Factory-Facility.ashx

            Container.Install(FromAssembly.This()).Install(FromAssembly.Named("APP.Infrastructure.DependencyResolution"));
            var controllerFactory = new WindsorControllerFactory(Container.Kernel);
            ControllerBuilder.Current.SetControllerFactory(controllerFactory);
        }

        public static void DeWire()
        {
            Container.Dispose();
        }
    }
}
...