Skip to content

Instantly share code, notes, and snippets.

@schotime
Created January 8, 2012 01:16
Show Gist options
  • Save schotime/1576721 to your computer and use it in GitHub Desktop.
Save schotime/1576721 to your computer and use it in GitHub Desktop.
Plugin Runner
public interface IActivity
{
void Run();
bool Matches(int i);
}
public class PluginRunner
{
private readonly IContainer _container;
private readonly ILogger _logger;
public PluginRunner(IContainer container, ILogger logger)
{
_container = container;
_logger = logger;
}
public void Run()
{
//var i = 0;
foreach (var activity in GetActivities().Where(activity => activity.Matches(1)))
{
activity.Run();
_logger.SetDebug();
}
}
private IEnumerable<IActivity> GetActivities()
{
if (Directory.Exists("plugins"))
{
_container.Configure(x => x.Scan(y =>
{
y.AssembliesFromPath("plugins");
y.AddAllTypesOf<IActivity>();
}));
}
return _container.GetAllInstances<IActivity>();
}
}
@jmarnold
Copy link

jmarnold commented Jan 8, 2012

Maybe you can change the configuration of your container to operate off of the new assemblies. So rather than a x.AssembliesFromPath(), you can pass in each new assembly so the scan operation is doing something more...let me fork this and show you.

@jmarnold
Copy link

jmarnold commented Jan 8, 2012

@schotime
Copy link
Author

schotime commented Jan 8, 2012

Then something like this?
https://gist.github.com/1577402

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment