I am working on an ASP.NET application split in to 4 layers.
- Business Layer
- Data Access Layer
- WCF Services Client
- ASP.NET MVC5 application
I am using AutoMapper to map from domain class to business class and other way around. I am using Data Annotation:
[StringLength(250)]
[Required(ErrorMessage = "Required Title")]
[Display(Name = "Function Title")]
Which is translated in view ASP.NET Razor page, i.e. creating record by passing strongly typed and validate against that. My question is how I can achieve this where I am passing business class to view as strongly typed and I don't want data dependency on business layer nor ASP.Net MVC application?
[Table("Navigation_Functions")]
public class Navigation_FunctionsEntity
{
public Navigation_FunctionsEntity()
{
}
[Key]
public int Function_ID { get; set; }
[StringLength(250)]
[Required(ErrorMessage = "Required Title")]
[Display(Name = "Function Title")]
public string FunctionName { get; set; }
[Required(ErrorMessage = "Required Hierarchy Level")]
[Display(Name = "Hierarchy Level")]
public int Hierarchy_Level { get; set; }
public ICollection<Navigation_FunctionHierarchy> Navigation_FunctionHierarchy { get; set; }
public ICollection<Navigation_FunctionInAction> Navigation_FunctionInAction { get; set; }
public ICollection<Navigation_FunctionInController> Navigation_FunctionInController { get; set; }
public ICollection<Navigation_FunctionController> Navigation_FunctionController { get; set; }
}
public class Navigation_Functions
{
public int Function_ID { get; set; }
public string FunctionName { get; set; }
public int Hierarchy_Level { get; set; }
public ICollection<Navigation_FunctionHierarchy> Navigation_FunctionHierarchy { get; set; }
public ICollection<Navigation_FunctionInAction> Navigation_FunctionInAction { get; set; }
public ICollection<Navigation_FunctionInController> Navigation_FunctionInController { get; set; }
public ICollection<Navigation_FunctionController> Navigation_FunctionController { get; set; }
}
My advice is don't organize your code into layers like this. It's a lot of hoops but there's no real advantage. In fact, I found over time that a layered architecture like this actually hinders refactoring and evolution of your codebase. Layers are for cake, not software.
I also question the value of WCF in your picture too, I don't know what it adds to the solution here except adding latency and making your requests slower.