Skip to content

Instantly share code, notes, and snippets.

@jmarnold
Forked from schotime/pluginrunner.cs
Created January 8, 2012 05:23
Show Gist options
  • Save jmarnold/1577334 to your computer and use it in GitHub Desktop.
Save jmarnold/1577334 to your computer and use it in GitHub Desktop.
Plugin Runner
public interface IActivity
{
void Run();
bool Matches(int i);
}
public class PluginActivator
{
private readonly IContainer _container;
public PluginActivator(IContainer container)
{
_container = container;
}
// call this for each new assembly
public void ActivateFrom(Assembly assembly)
{
_container.Configure(x =>
{
x.Scan(s =>
{
s.Assembly(assembly);
s.AddAllTypesOf<IActivity>();
});
});
}
}
public class PluginRunner
{
private readonly ILogger _logger;
private readonly IEnumerable<IActivity> _activities;
public PluginRunner(ILogger logger, IEnumerable<IActivity> activities)
{
_logger = logger;
_activities = activities;
}
public void Run()
{
//var i = 0;
foreach (var activity in _activities.Where(activity => activity.Matches(1)))
{
activity.Run();
_logger.SetDebug();
}
}
}
@schotime
Copy link

schotime commented Jan 8, 2012

Cheers....I will flesh it out in my mind. I would then have to store a list of loaded files so that I can only load new ones.

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