I am working on a new MVC web application, so the project is in early stages. I have created 4 projects.
Let me explain what they do:
Common --> contains all my DTOs, enums helpers, ViewModels etc.
Web --> simple MVC application
Business --> This contains providers which have an interface and implementation for dependency injection:
DAL --> Contains edmx file and DB Entities
DAL is similar to Business project. It has an IUsersDAL
and then UsersDAL
implementation.
Do I really need the DAL classes to access the database, or can I just access them from the Business class?
Just for an example I am adding a sample code from UsersProvider.cs:
This what my BusinessProvider
is doing:
private readonly IXPTSecurity _security;
private readonly IUsersDAL _usersDAL;
public UsersProvider(IXPTSecurity xptSecurity, IUsersDAL usersDAL)
{
_security = xptSecurity;
_usersDAL = usersDAL;
}
public UserSessionModel AuthenticateUser(string userName, string password, ValidationContainer validationContainer)
{
var userInfo = _usersDAL.GetUserByUserNamePassword(userName, _security.Encrypt(password));
if (userInfo == null)
{
validationContainer.AddMessage(MessageType.Error, "Login Failed. User name or password is incorrect.");
return null;
}
}
And then this is what is happening in the _usersDal.GetUserByUserNamePassword()
:
// So this is this is what UsersDAL is doing
public User GetUserByUserNamePassword(string userName, string password)
{
return _managerEntities.Users.FirstOrDefault(s => s.sUserName == userName && s.sPassword == password);
}
As you can see, all I am doing in my DAL classes is a simple LINQ type read from the database. If I do this in the Providers it saves me an extra layer.
It would be nice to get someone else opinion on this before I start coding.
By the way I need a separate Common and Business because this project requires another web application and another 3,4 Windows services, which will be later added using the same Business and Common. But I am not sure on the DAL.