开发者

Creating plugin scanner with StructureMap

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

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜