5

Problem: Loading Plugins into a console app(Windows Service Eventually) and running code in the plug in dll's

Research: StructureMap Docs(of course) A few stackoverflow threads this one being the closest. Creating plugin scanner with StructureMap

I have 3 projects: Console App (Driver) 2 Class libraries

Console App

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!");
    }
}

The Output:

ObjectFactory.GetAllInstances<IPlugable>();

returns no objects :( Desired Output: 2 Object Instances of Plugin_1 & Plugin_2

Thanks in advance.

1
  • Show the output of ObjectFactory.WhatDoIHave() Commented May 10, 2011 at 19:26

2 Answers 2

2

Looks like you are using 3 different interfaces. They are all called "IPlugable", but reside in different namespaces, hence they are not the same.

Sign up to request clarification or add additional context in comments.

Comments

1

I think this is the answer I am going with.. Managed Extensibility Framework http://msdn.microsoft.com/en-us/library/dd460648.aspx

Got to love it when you find a new framework to find the exact solution to your problem.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.