Skip to content

Instantly share code, notes, and snippets.

@timwingfield
Created June 10, 2010 12:37
Show Gist options
  • Save timwingfield/432925 to your computer and use it in GitHub Desktop.
Save timwingfield/432925 to your computer and use it in GitHub Desktop.
poor man's DI, repo, service, etc, etc
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