Skip to content

Instantly share code, notes, and snippets.

@brunomlopes
Last active September 6, 2015 14:24
Show Gist options
  • Save brunomlopes/c98636601d88df0c3de2 to your computer and use it in GitHub Desktop.
Save brunomlopes/c98636601d88df0c3de2 to your computer and use it in GitHub Desktop.
using System;
using Microsoft.Framework.DependencyInjection;
namespace weListen.Infrastructure.Workers.Sanitization
{
public static class ExtensionMethods
{
public static IServiceCollection RegisterEngines(this IServiceCollection services)
{
return services.AddScoped<EngineA>()
.AddScoped<EngineB>()
.AddScoped<IEngine, EngineSelector>();
}
}
public class EngineSelector : IEngine
{
private readonly EngineA _engineA;
private readonly EngineB _engineB;
public EngineSelector(EngineA engineA, EngineB engineB)
{
_engineA = engineA;
_engineB = engineB;
}
public void DoStuff()
{
if (SelectA())
{
_engineA.DoStuff();
}
else
{
_engineB.DoStuff();
}
}
private bool SelectA()
{
throw new NotImplementedException();
}
}
public class EngineA : IEngine
{
public void DoStuff()
{
}
}
public class EngineB : IEngine
{
public void DoStuff()
{
}
}
public interface IEngine
{
void DoStuff();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment