Perhaps my questions here and here are not clear enough, so I will try to reduce verbosity without diminishing clarity.
Let's say my controller uses DI (you can verbalize it "in your head" - you do not need to pronounce it out loud); so it might look like this:
private readonly IDepartmentRepository _deptsRepository;
public DepartmentsController(IDepartmentRepository deptsRepository)
{
if (deptsRepository == null)
{
throw new ArgumentNullException("deptsRepository is null");
}
_deptsRepository = deptsRepository;
}
That way, I can intercept the web API routing mechanism by passing it a specific class that implements the IDepartmentRepository for the Controller constructor. So if my interface is:
public interface IDepartmentRepository
{
int Get();
IEnumerable<Department> Get(int ID, int CountToFetch);
Department Add(Department item);
void Post(Department dept);
void PostDepartment(int accountid, string name);
void Put(Department dept);
void Delete(int Id);
}
... I could have classes like this:
public class DepartmentRepositoryProductionData : IDepartmentRepository
{
private readonly List<Department> departments = new List<Department>();
public DepartmentRepository()
{
using (var conn = new OleDbConnection(
@"Provider=Microsoft.ACE.OLEDB.12.0;User ID=BlaBlaBla..."))
{
...
... and this:
public class DepartmentRepositoryTestData : IDepartmentRepository
{
private readonly List<Department> departments = new List<Department>();
public DepartmentRepository()
{
...
, dandy, / , , DepartmentRepositoryTestData ( DepartmentRepositoryProductionData) , Controller? , DI, , , ( )
, IOW , URI? , , " ".
UPDATE
, :
( arg Controller) - , , , ? " " " ", "California Pizza" "New York Pizza", , -, , IPizzaPie.
- - , : " " " -" ..
: / ( ) , ?
2
, , , , - ( "WindsorCompositionRoot.cs" ) :
public IHttpController Create(
HttpRequestMessage request,
HttpControllerDescriptor controllerDescriptor,
Type controllerType)
{
var controller =
(IHttpController)this.container.Resolve(controllerType);
request.RegisterForDispose(
new Release(
() => this.container.Release(controller)));
return controller;
}
... , (IHttpController)...
3
, this