Created
March 2, 2010 18:54
-
-
Save actaneon/319792 to your computer and use it in GitHub Desktop.
Composition and IoC for OCP Adherence
This file contains 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 Composition and IoC to add a logging to the IService implementation without violating OCP. | |
//Instantiate with: For<IService>.Use<LoggingService>().Ctor<IService>().Is<SomeService>(); | |
// | |
//create a LoggingService : IService that takes the *real* IService in it's c'tor | |
public class LoggingService : IService | |
{ | |
private IService _realService; | |
private ILogger _log; | |
public LoggingService(IService realService, ILogger log) | |
{ | |
_realService = realService; | |
_log = log; | |
} | |
public void DoStuff() | |
{ | |
_log.Log("Doing some stuff"); | |
_realService.DoStuff(); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment