从程序集中加载温莎城堡安装程序时出现问题

发布于 2024-12-22 16:25:09 字数 876 浏览 0 评论 0原文

这可能是一个愚蠢的问题!我被迫使用温莎城堡作为我的 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));
    }

控制器工厂可以工作,但仅此而已。我的安装程序也有一个单独的项目,我希望它能够从当前 Web 项目中的程序集加载任何安装程序(我可能需要你知道的东西)。

使用 IWindsorInstaller 的 DI 项目中的类根本没有被加载。 我错过了什么吗?

在 Ninject 中我们可以使用

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

This is probably a stupid question! I am being forced to use Castle Windsor as my IOC and am having some issues getting things setup with MVC.
Here is what I have.

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));
    }

The controller factory works but that is about it. I have a separate project with my installers as well I wold like it to load any installers from assemblies in the current web project(I may need something there ya know).

The classes in the DI project using IWindsorInstaller are not being loaded at all.
Am I missing something?

In Ninject we could use

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

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

感性 2024-12-29 16:25:09

我最终在 App_Start 中使用了 WebActivator

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();
        }
    }
}

I ended up using WebActivator in 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();
        }
    }
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文