Can somebody please explain:
- I am using MVC3/C#/Razor to build a project to get used to using MVC.
- I am using the inbuilt account controller.
I am storing the account data in my local SQL database using Entity Framework to connect.
How can I easily generate interfaces for EF?SO FAR I am using the plugin from: http://blog.johanneshoppe.de/2010/10/walkthrough-ado-net-unit-testable-repository-generator/#step1
This allows me to have an interface for my entities already created.
Howeve开发者_运维技巧r, I know that I have to change myHomeController
arguments to accept either the real repository or a fake one for testing.
I am completely lost!
Have a look at these. They will help and get you started :
http://www.asp.net/entity-framework/tutorials/implementing-the-repository-and-unit-of-work-patterns-in-an-asp-net-mvc-application
http://msdn.microsoft.com/en-us/library/gg416511(VS.98).aspx
For dependency injection, you can follow these steps :
Install-Package Ninject.MVC3
with nuget to your ASP.NET MVC 3 project (if your app is on version 3). This will basically do everything.
Then have the following on your controller :
private IMyModelRepository _myrepo;
public HomeController(IMyModelRepository myrepo)
{
_myrepo = myrepo;
}
Go to NinjectMVC3.cs file inside App_Start folder and add the following code to inside RegisterServices
method :
private static void RegisterServices(IKernel kernel) {
kernel.Bind<IMyModelRepository>().To<MyModelRepository >();
}
Fire up your app and you should be up and running.
精彩评论