Last active
September 6, 2015 14:24
-
-
Save brunomlopes/c98636601d88df0c3de2 to your computer and use it in GitHub Desktop.
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
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