-
-
Save jmarnold/1577334 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 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(); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.