开发者

MVC3 & EF. Interface for TDD

开发者 https://www.devze.com 2023-04-08 06:45 出处:网络
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.

Can somebody please explain:

  1. I am using MVC3/C#/Razor to build a project to get used to using MVC.
  2. I am using the inbuilt account controller.
  3. I am storing the account data in my local SQL database using Entity Framework to connect.

    How can I easily generate interfaces for EF?

  4. 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 my HomeController 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.

0

精彩评论

暂无评论...
验证码 换一张
取 消