开发者

When Using the Service Layer Pattern, Is there a Folder Layout Convention for a Visual Studio 2010 Solution?

开发者 https://www.devze.com 2023-04-12 15:49 出处:网络
I want to use the Service Layer patter (as described on Marti开发者_开发知识库n Fowler\'s site here) for my ASP.NET MVC 3 application.

I want to use the Service Layer patter (as described on Marti开发者_开发知识库n Fowler's site here) for my ASP.NET MVC 3 application.

My goal is to setup the solution structure in a way for me to more easily learn the pattern by setting up the proper framework for it prior to digging into the code.

Can anyone show me the conventional way to layout the solution, projects, and folders within a Visual Studio 2010 Solution?


There are many ways to implement this. Either segment the service layer into a separate assembly or it could be in the same assembly as the ASP.NET MVC application (for example in a Services folder). There is really no rule for that. It will depend on the level of reusability you are expecting from this layer and the size of your project. What is important though is to abstract this service layer:

public interface IMyService
{
    ... some service methods
}

and then have your controllers work only with this abstraction:

public class MyController: Controller
{
    private readonly IMyService _service;
    public MyController(IMyService service)
    {
        _service = service;
    }

    public ActionResult MyAction()
    {
        ... call some methods on the service layer
    }
}

Then to wire up the concrete implementation you would configure your dependency injection framework.

0

精彩评论

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

关注公众号