StructureMap:如何在与ConnectImplementationsToTypesClosing连接的类型上设置生命周期 [英] StructureMap: How to set lifecycle on types connected with ConnectImplementationsToTypesClosing

查看:91
本文介绍了StructureMap:如何在与ConnectImplementationsToTypesClosing连接的类型上设置生命周期的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在注册表中有

Scan(scanner =>
         {
             scanner.AssemblyContainingType<EmailValidation>();
             scanner.ConnectImplementationsToTypesClosing(typeof(IValidation<>));
         });

我应该怎么做才能将所有这些都定义为Singletons?

What am I supposed to do to define these all as Singletons?

除了这个问题之外,是否有任何理由不将无状态的所有内容都定义为在StructureMap中注册的单例对象?

Also as an aside to this question, is there any reason to not define everything that is stateless as a singleton object that's registered in StructureMap?

推荐答案

Kevin的答案对于2.5.4和更早的版本是正确的.在当前的StructureMap主干(以及2.5.5+发行版中)中,您现在可以执行以下操作:

Kevin's answer is correct for versions 2.5.4 and older. In the current StructureMap trunk (and when 2.5.5+ is released), you can now do:

Scan(scanner =>
{
   scanner.AssemblyContainingType<EmailValidation>();
   scanner.ConnectImplementationsToTypesClosing(typeof(IValidation<>))
          .OnAddedPluginTypes(t => t.Singleton());
});

这篇关于StructureMap:如何在与ConnectImplementationsToTypesClosing连接的类型上设置生命周期的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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