Created
January 8, 2012 01:16
-
-
Save schotime/1576721 to your computer and use it in GitHub Desktop.
Plugin Runner
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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>(); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Then something like this?
https://gist.github.com/1577402