Castle Windsor - 注册所有Windows窗体

时间:2014-04-10 13:25:27

标签: winforms castle-windsor autofac

这是使用autofac

的方法
var assembly = Assembly.GetExecutingAssembly();
builder.RegisterAssemblyTypes(assembly)
    .Where(type => type.IsSubclassOf(typeof(Form)));

var assembly = Assembly.GetExecutingAssembly();
builder.RegisterAssemblyTypes(assembly)
    .AssignableTo<Form>();

如何使用Castle Windsor做到这一点?

1 个答案:

答案 0 :(得分:0)

这样的事情应该有效(从记忆中输入):

container.Register(
   Classes.FromAssembly(Assembly.GetExecutingAssembly())
      .BasedOn<Form>()
      .Configure(c => c.Lifestyle.Transient)
);

Configure选项并非必需,但我的获胜形式通常是暂时的。

查看registration docs了解更多选项。