it:ad:structuremap:howto:register_instances_against_open_contracts

IT:AD:StructureMap:HowTo:Register Instances against Open Contracts

Summary

Got to admit that a feature like this does make you question why I use IT:AD:Unity so often…

  //Notice how it's an open type:
  Type closingType = typeof(IUnitTestDbContextSeeder<>);

  ObjectFactory
    .Initialize(config => config.Scan(scanner =>
      {
        scanner.Assembly(GetType().Assembly);//this assembly only... 
        scanner.IncludeNamespaceContainingType<DefaultStudentSeeder>();//this ns only... 
        scanner
          //register types implementing open contract as singletons:
          .ConnectImplementationsToTypesClosing(closingType) //<-- NEAT!
          .OnAddedPluginTypes(expression => expression.Singleton()); //as singletons
    }
  ));

  • /home/skysigal/public_html/data/pages/it/ad/structuremap/howto/register_instances_against_open_contracts.txt
  • Last modified: 2023/11/04 01:58
  • by 127.0.0.1