I am new in Asp.Net MVC and want to split my project into layerd architecture having 1- MVC Project (presentation layer UI layer) 2- Business Logic Layer BLL (here i want to validate data View Model and convert View Model to Database Model using auto mapper and then want to send back View Model by convert back by using auto mapper to ui (MVC Project) layer 3- Data Access Layer having repositories DB Context etc which i want to referenced only in business layer.
my confusion is in between business logic layer and MVC Project (UI) layer. my view model classes are in Model folder inside MVC project and Business logic layer have reference of Data Access Layer having database table classes. so my view model are not recognized in business logic layer. if i want to add MVC project (where my view model exist) reference to business logic layer it give circular dependencies error. i do lot of search on forums and tutorials but failed to find solution or failed to understand the concept.
my business logic layer and data access layer are library project while UI layer is MVC project
if any body can explain with example by send data view model to business logic layer and receive back view model from business logic layer
Data Access Layer
namespace DAL.Infrastructure.Contract
{
public interface IBaseRepository<T> : IDisposable where T : class
{
IEnumerable<T> GetAll();
IEnumerable<T> FindIEnumerableByExpression(Expression<Func<T, bool>> predicate);
T FindFirstOrDefaultByExpression(Expression<Func<T, bool>> predicate);
T GetById(object Id);
T Insert(T entity);
T Delete(T entity);
void Update(T entity);
void Save();
}
}
namespace DAL.Infrastructure
{
public class BaseRepository<T> : IBaseRepository<T> where T : class
{
public PMSEntities dbContext = null;
public DbSet<T> dbSet = null;
public BaseRepository()
{
this.dbContext = new PMSEntities();
dbSet = dbContext.Set<T>();
}
public virtual IEnumerable<T> GetAll()
{
return dbSet.AsEnumerable<T>();
}
public T GetById(object id)
{
return this.dbSet.Find(id);
}
public IEnumerable<T> FindIEnumerableByExpression(System.Linq.Expressions.Expression<Func<T, bool>> predicate)
{
IEnumerable<T> query = dbSet.Where(predicate).AsEnumerable();
return query;
}
public T FindFirstOrDefaultByExpression(System.Linq.Expressions.Expression<Func<T, bool>> predicate)
{
return this.dbSet.FirstOrDefault(predicate);
}
public virtual T Insert(T entity)
{
return dbSet.Add(entity);
}
public virtual T Delete(T entity)
{
return dbSet.Remove(entity);
}
public virtual void Update(T entity)
{
dbContext.Entry(entity).State = System.Data.Entity.EntityState.Modified;
}
public void Save()
{
dbContext.SaveChanges();
}
private bool disposed = false;
protected virtual void Dispose(bool disposing)
{
if (!this.disposed)
{
if (disposing)
{
dbContext.Dispose();
}
}
this.disposed = true;
}
public void Dispose()
{
Dispose(true);
GC.SuppressFinalize(this);
}
}
}
i want to use this above class in business logic layer not direct in controller. here is my confusion how to write business logic layer and use auto mapper in business logic layer having error of circular dependencies