I have been reading tons of threads and still not sure i get it. First of all i want to verify that i get the basics "correct" or atleast it's an ok way to start a smaller project.
- No Unit test will be written
- No complext models will exists (Just alot of CRUD operations)
- No business rules (I think)
I will start with the following structure in my solution:
Web.Domain.entities
I using ValidationAttributes on my properties, and i should belong to my ViewModel instead, but don't think i need a ViewModel, or don't really see the need of one (I just have to mapp everything twice?)
namespace Web.Domain.Entities
{
public class Car
{
public int Id { get; set; }
[Required(ErrorMessage = "RegNumber missing.")]
public string RegNumber { get; set; }
public Car() { }
public Car(IDataReader reader)
{
Id = Helper.GetSafeInt(reader, "Id");
RegNumber = Helper.GetSafeString(reader, "RegNumber");
}
}
}
Project structure
Web.MVC
- Basic folder for my MVC application.
Web.MVC.Views
- Handling presentation of my Entities (Not have ViewModels)
Web.MVC.ViewModels
- Not used, but i used it is this the correct place to store it?
Web.DAL
- Static classes with static methods, CRUD operations.
Web.DAL.CarDAL
- Static class, don't want to create a new instance every time, cleaner code.
Web.DAL.CarDAL.Get()
- Static method, CRUD operations.
My Controller looks like this,
public ActionResult Get()
{
var data = Web.DAL.CarDAL.Get();
return View(data);
}
As i looks like right now i need to reference my Web.Domain.entities
from both Web.MVC.Controller
and Web.DAL.CarDAL
.
If i want to create some business logic, some recommend it to live within the Entities, is this a good place?
namespace Web.Domain.Entities
{
public class Car
{
public int Id { get; set; }
[Required(ErrorMessage = "RegNumber missing.")]
public string RegNumber { get; set; }
public Car() { }
public Car(IDataReader reader)
{
Id = Helper.GetSafeInt(reader, "Id");
RegNumber = Helper.GetSafeString(reader, "RegNumber");
}
public void BusinessRule1(string regNumber)
{
throw new Exception("BusinessRule1 failed.");
}
}
}
And if start to use a ViewModel it really just seams like a copy of my Entity.
Feel free to comment anything about the above structure/code, and motivate way i need to do the change you say.
Aucun commentaire:
Enregistrer un commentaire