StructureMap Dll's Dynamic Download Plugin

Problem: Downloading plugins in a console application (Windows service in the end) and running code in a dll plugin

Research: Documents StructureMap (of course) Several stackoverflow threads are one of the closest. Creating a plug-in scanner with StructureMap

I have 3 projects: Console application (driver) 2 class libraries

Console application

static void Main(string[] args)
{
    ObjectFactory.Initialize(cfg => cfg.Scan(scanner =>
    {
        scanner.AssembliesFromPath(@"PATH TO PLUGIN DIR");
        scanner.AddAllTypesOf<IPlugable>();
    }));

    var list = ObjectFactory.GetAllInstances<IPlugable>();

    foreach (var plug in list)
    {
        plug.Run();
    }
}

public interface IPlugable
{
    void Run();
}

Plugin_2

public interface IPlugable
{      
    void Run();
}

public class PlugIn2 : IPlugable
{    
    public void Run()
    {
        Console.WriteLine(this.GetType().Name + "fired!");
    }
}

public interface IPlugable
{     
    void Run();
}

public class PlugIn1 : IPlugable
{          
    public void Run()
    {
        Console.WriteLine(this.GetType().Name + "fired!");
    }
}

Output:

ObjectFactory.GetAllInstances<IPlugable>();

does not return objects :( Desired result: 2 instances of the object Plugin_1 and Plugin_2

Thanks in advance.

+5
source share
2 answers

, 3 . "IPlugable", , .

+2

All Articles