Skip to content

Instantly share code, notes, and snippets.

@JakeGinnivan
Created August 21, 2013 06:16
Show Gist options
  • Select an option

  • Save JakeGinnivan/6290877 to your computer and use it in GitHub Desktop.

Select an option

Save JakeGinnivan/6290877 to your computer and use it in GitHub Desktop.
public class FooController : Controller{
IService service;
public FooController(IService service){
this.service = service;
}
public ActionResult Bar(){
service.DoStuff();
}
}
public interface IService {
void DoStuff();
}
public class MockService : IService{
...
}
public class RealService : IService {
...
}
public class ServiceSwitcher : IService {
RealService realService;
MockService mockService;
public ServiceSwitcher(RealService realService, MockService mockService){
this.realService = realService;
this.mockService = mockService;
}
public void DoStuff(){
if (Condition())
mockService.DoStuff();
else
realService.DoStuff();
}
}
void COntainerRegistration(){
var cb = new ContainerBuilder();
cb.RegisterType<RealService>().AsSelf();
cb.RegisterType<MockService>().AsSelf();
cb.RegisterType<ServiceSwitcher>().As<IService>();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment