开发者

Business Logic + ASP.NET MVC

I've an MVC application, which is divided into 3 layers: - Presentation - ASp.NET MVC - Busines Logic - Here we have entities and object services. We alo have mappers between DAL objects and BL objects - Data Access Layer - we use EF to query the database. Now, we've created a factory for object services, and the factory is injected into presentation later using Unity. Each time I want to do some logic, I call an appropriate service which uses DAL repositories to do some stuff. Now, silly question, let suppose that I want to check if I can add a user with a provided nickname. The nickname is unique in the database, so before I add the user, I check if a user with provided nickname exists. So, it's a simple query that returns true/f开发者_Go百科alse. Becuase I don't have any connections between presentation layer and business layer, I check it in the service. But the code of the service method simply looks like:

var exists = repository.NicknameExists(nickname);
return exists;

The code above is strange, because it does nothing, just calls a method and returns its value. On the other hand, I've Separation of Concerns, so my solution is well organised. Can someone give me some suggestions, how should I solve problems like that?


I don't see any problem here. It's perfect method for me:

public bool IsUserExists(string nickname)
{
    return repository.NicknameExists(nickname);
}

I would recomend to you to read this blog post about valid reasons to create a routine or the chapter 7.1 of the Code Complete 2ed

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜