首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Spring.Net是否有任何基于约定的绑定(如Ninject.Extensions.Conventions)

Spring.Net是否有任何基于约定的绑定(如Ninject.Extensions.Conventions)
EN

Stack Overflow用户
提问于 2011-04-20 15:20:57
回答 3查看 275关注 0票数 1

我熟悉尼尼姆,但不熟悉Spring.Net。我正在试图确定在Spring.net中是否存在与“Spring.net”相当的“”。允许基于约定的映射的东西。例如,一些允许我定义如下规则的东西:

  • 期望给定名称空间或程序集中的所有具体类都有一个具有相同名称的相应接口,但前缀为I。

谢谢

EN

回答 3

Stack Overflow用户

回答已采纳

发布于 2011-04-20 15:43:24

不,Spring.NET几乎没有代码作为配置,所以自动注册是完全不可用的.

票数 1
EN

Stack Overflow用户

发布于 2011-06-28 00:13:45

Spring.net使用一种不同的方法,它们有依赖于属性的CodeConfig,基本上您可以在类中设置一些属性,以便DI容器知道需要注入哪些类。您可以找到更多的信息,这里

对我来说,配置IOC的最好方法是使用xml文件,因为您可以控制应用程序的行为,而无需编译任何东西,即使在生产环境中也是如此。

票数 1
EN

Stack Overflow用户

发布于 2012-12-31 00:58:09

还有一个使用Spring.AutoRegistration的选项。统一AutoRegistration中使用的相同概念。

http://rafaelnaskar.blogspot.com.br/2012/12/springautoregistration-fluent.html

https://www.nuget.org/packages/Spring.AutoRegistration

代码语言:javascript
复制
    var context = new GenericApplicationContext();
    context.Configure()
            .IncludeAssembly(x => x.FullName.StartsWith("Company.ApplicationXPTO"))
            .Include(x => x.ImplementsITypeName(), Then.Register().UsingSingleton()
                  .InjectByProperty(If.DecoratedWith<InjectAttribute>))
            .ApplyAutoRegistration();

       var context = new GenericApplicationContext();
       context.Configure()
            .Include(If.DecoratedWith<NamedAttribute>,Then.Register().UsingSingleton().InjectByProperty(If.DecoratedWith<InjectAttribute>))
            .Include(If.Implements<IController>, 
                Then.Register().UsingPrototype().InjectByProperty(If.DecoratedWith<InjectAttribute>))
            .ApplyAutoRegistration();



        var context = new GenericApplicationContext();
        context.Configure()
            .IncludeAssembly(x => x.FullName.StartsWith("Spring.AutoRegistration.Test"))
            .Include(x => x.GetInterfaces().Length > 0, 
                Then.Register().WithNamedAttributeIfExists().UsingPrototype()
                    .InjectByProperty(If.DecoratedWith<InjectAttribute>))
            .ApplyAutoRegistration();
票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/5732742

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档