Skip to content

Instantly share code, notes, and snippets.

@actaneon
Created March 2, 2010 18:54
Show Gist options
  • Select an option

  • Save actaneon/319792 to your computer and use it in GitHub Desktop.

Select an option

Save actaneon/319792 to your computer and use it in GitHub Desktop.

Revisions

  1. actaneon created this gist Mar 2, 2010.
    21 changes: 21 additions & 0 deletions CompositionAndOCP.cs
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,21 @@
    //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();
    }
    }