Is there a .NET IoC that prefers convention over configuration?

后端 未结 6 984
天涯浪人
天涯浪人 2021-02-04 17:03

Simply put, if you had to use a IoC/DI container, thats easy to deploy (not a big fan of using config/xml file for everything), stable, good documentation and supports .net, whi

6条回答
  •  情话喂你
    2021-02-04 17:35

    The latest version of StructureMap, 2.5.2, not only lets you configure your container without XML as Ryan said but it also has the ability to AutoWire things according to a convention, which seems to be exactly what you're looking for.

    ObjectFactory.Initialize(x => x.Scan(scanner =>
                                            {
                                               scanner.TheCallingAssembly();
                                               scanner.WithDefaultConventions();
                                            }));;
    

    From the docs on IAssemblyScanner.WithDefaultConvents():

    Adds the DefaultConventionScanner to the scanning operation. i.e., a concrete class named "Something" that implements "ISomething" will be automatically added to the PluginType "ISomething"

    I've not personally done much with it as I already had the existing configuration that used the Fluent Interface. But it looks promising.

    EDIT: Jeremy Miller just put up a post on how to create your OWN Conventions...

提交回复
热议问题