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>();
});
精彩评论