Created
June 10, 2010 12:37
-
-
Save timwingfield/432925 to your computer and use it in GitHub Desktop.
poor man's DI, repo, service, etc, etc
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 System.Collections.Generic; | |
using System.Linq; | |
using System.Text; | |
namespace CODODN | |
{ | |
public interface IRepository | |
{ | |
string SomethingYouNeed { get; set; } | |
} | |
public class repository : IRepository | |
{ | |
public string SomethingYouNeed | |
{ | |
get | |
{ | |
return "Production Item"; | |
} | |
set | |
{ | |
throw new NotImplementedException(); | |
} | |
} | |
} | |
public class my_service | |
{ | |
IRepository _repo; | |
public my_service() : this(null){} | |
public my_service (IRepository repo) | |
{ | |
_repo = repo ?? new repository(); | |
} | |
} | |
public class test_service_class | |
{ | |
//inject the repo | |
public void before_each() | |
{ | |
var s = new my_service(new fake_repository()); | |
} | |
} | |
public class fake_repository : IRepository | |
{ | |
public string SomethingYouNeed | |
{ | |
get | |
{ | |
return "My Test Doo-Dad"; | |
} | |
set | |
{ | |
throw new NotImplementedException(); | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment