I'm reading Sanderson's "Pro ASP.NET MVC Framework". I'm confused a little with decoupling implementation.
He uses LinqToSql in the code sample and repository pattern to interact with database.
[Table(Name = "Products")]
public class Product
{
[Column(IsPrimaryKey = true, IsDbGenerated = true, AutoSync=AutoSync.OnInsert)]
public int ProductID { get; set; }
[Column]
public string Name { get; set; }
[Column]
public string Description { get; set; }
[Column]
public decimal Price { get; set; }
[Column]
public string Category { get; set; }
}
public class SqlProductsRepository : IProductsRepository
{
private Table<Product> productsTable;
public SqlProductsRepository(string connectionString)
{
productsTable = (new DataContext(connectionString)).GetTable<Product>();
}
public IQueryable<Product> Products
{
get { return productsTable; }
}
}
SqlProductsRepository is dataLayer here as it interacts with database. 1.However it is located in DomainModel project. Maybe it is just for demo? So where is domain logic here?
2.I can't see full decoupling as Products property return IQueryable. Is it assumed that if we change a component, it must contain Product class? I seem that it is required to have one more project with abstractions: Repository Interfaces such as IProductRepository and MappingClasses interfaces such as IProduct. DataLayer component must implement these abastractions. Is it right?
Maybe it is diffucult to explain it shortly, however how it is usually work in live projects?