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>(); | |
} | |
} |
It still needs to scan all of them each time to find out which one is needed to be run.
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.
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
Mostly performance. Maybe something more like "find the activities from these assemblies". As it stands right now, every plugin you have is going to rerun whenever a new assembly is dropped