问题在diferent项目有分开的控制器的ControllerFactory [英] Problem with ControllerFactory having controllers separated in a diferent project

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

问题描述

我有一个不同的项目分开我的控制器,我使用温​​莎城堡,一切都很好,我在同一个项目中的tipical控制器工厂做如下:

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

然后我就想工厂recapsulate到自己的框架重用它在未来的项目。但随后的执行大会这么想的有控制器,如何让它脱钩任何想法?

Then I wanted to recapsulate the factory to an own "Framework" to reuse it in future projects. But then the executing assembly dosen'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...

谢谢!

推荐答案

首先,我想传递一个大会的构造函数的参数,那么我将创建一个工厂方法:

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

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

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