开发者

Creating plugin scanner with StructureMap

开发者 https://www.devze.com 2023-02-17 04:34 出处:网络
I\'m attempting to write a StructureM开发者_开发技巧ap plugin scanner for Payment Gateway implementations.I have created an IPaymentGateway interface in an external library.I have created several impl

I'm attempting to write a StructureM开发者_开发技巧ap plugin scanner for Payment Gateway implementations. I have created an IPaymentGateway interface in an external library. I have created several implementations of IPaymentGateway and put those .dlls in my C:\Extensions\ folder.

Here is my StructureMap configuration:

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

Here is my calling code:

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

I would expect that the list should contain each of my implementations of IPaymentGateway, but it doesn't contain anything. What am I missing?

Thanks!


You need to add the types using the scanner:

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

精彩评论

暂无评论...
验证码 换一张
取 消