Creating a Scanner Plugin with StructureMap

I am trying to write a StructureMap plugin for implementing a Payment Gateway. I created the IPaymentGateway interface in an external library. I created several implementations of IPaymentGateway and put these .dlls in the C: \ Extensions \ folder.

Here is my StructureMap configuration:

         ObjectFactory.Initialize(cfg =>
        {
            cfg.Scan(scanner =>
            {
                scanner.AssembliesFromPath(@"C:\Extensions\");
            });
        });

Here is my code:

var list = ObjectFactory.GetAllInstances<IPaymentGateway>().ToList();
list.ForEach(item => Console.WriteLine(item.FriendlyName));

I would expect the list should contain each of my IPaymentGateway implementations, but it does not contain anything. What am I missing?

Thank!

+2
source share
1 answer

You need to add types using a scanner:

ObjectFactory.Initialize(cfg => {
    cfg.Scan(scanner =>
    {
      scanner.AssembliesFromPath(@"C:\Extensions\");
      scanner.AddAllTypesOf<IPaymentGateway>();
    });
+2
source

All Articles