ControllerFactory具有在不同项目中分开的控制器 [英] ControllerFactory having controllers separated in a different project

查看:65
本文介绍了ControllerFactory具有在不同项目中分开的控制器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的控制器分别位于一个不同的项目中,我正在使用温莎城堡,并且一切都很好,我在同一个项目中有一个典型的控制器工厂,可以进行以下操作:

I have my controllers separated in a different project, i'm using castle windsor and everything was fine, i had a tipical Controller factory in the same project that do the follow:

        public WindsorControllerFactory()
    {
        container = new WindsorContainer(
                        new XmlInterpreter(new ConfigResource("castle")
                        )
                    );

        var controllerTypes = from t in Assembly.GetExecutingAssembly().GetTypes()
                          where typeof(IController).IsAssignableFrom(t)
                          select t;

        foreach (Type t in controllerTypes)
        {
            container.AddComponentLifeStyle(t.FullName, t, Castle.Core.LifestyleType.Transient);
        }
    }

然后,我想将工厂重新封装为自己的框架",以在以后的项目中重复使用.但是执行的程序集没有控制器,关于如何使其解耦的任何想法?

Then I wanted to recapsulate the factory to an own "Framework" to reuse it in future projects. But then the executing assembly doesn't have the controllers, Any ideas about how to make it decoupled?

我在考虑一个类似配置文件的文件,该文件指示了控制器的组装...

I was thinking in something like a configuration file that indicates the assembly with the controllers...

推荐答案

首先,我将Assembly作为构造函数参数传递,然后创建一个工厂方法:

First of all, I would pass an Assembly as constructor parameter, then I would create a factory method:

public static IControllerFactory FromAssemblyContaining<T>()
{
    return new WindsorControllerFactory(typeof(T).Assembly);
}

然后使用以下命令创建控制器工厂:

And then create your controller factory using:

WindsorControllerFactory.FromAssemblyContaining<some class, Global perhaps>();

这篇关于ControllerFactory具有在不同项目中分开的控制器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆