Creating plugin scanner with StructureMap

让人想犯罪 __ 提交于 2019-12-12 09:59:46

问题


I'm attempting to write a StructureMap 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!


回答1:


You need to add the types using the scanner:

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


来源:https://stackoverflow.com/questions/5299510/creating-plugin-scanner-with-structuremap

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!