Ciao, sono riuscito ad implementare il Repository Pattern nella mia applicazione, e ho correttamente creato L'Entity Models con le le entità Product, Category, ecc...
A questo punto vi posto il codice del ProductRepository
Namespace Repository
Public Class ProductRepository
Inherits BaseRepository(Of Product)
Implements IProductRepository
Public Function FindById(ByVal int As Integer) As Common.Model.Product Implements Common.Repository.IReadOnlyRepository(Of Common.Repository.IProductRepository, Common.Model.Product).FindById
Return Me.Where(Function(c) c.ID = int).First ' richiamo il metodo Where di questa classe / repository
End Function
Public Function GetAll() As System.Linq.IQueryable(Of Common.Model.Product) Implements Common.Repository.IReadOnlyRepository(Of Common.Repository.IProductRepository, Common.Model.Product).GetAll
Return CurrentObjectSet
End Function
Public Function Include(ByVal str As String) As Common.Repository.IProductRepository Implements Common.Repository.IReadOnlyRepository(Of Common.Repository.IProductRepository, Common.Model.Product).Include
CurrentObjectSet.Include(str)
Return Me
End Function
Public Function Count(ByVal predicate As System.Linq.Expressions.Expression(Of System.Func(Of Common.Model.Product, Boolean))) As Long Implements Common.Repository.IReadOnlyRepository(Of Common.Repository.IProductRepository, Common.Model.Product).Count
Return CurrentObjectSet.Where(predicate).Count
End Function
Public Function Where(ByVal predicate As System.Linq.Expressions.Expression(Of System.Func(Of Common.Model.Product, Boolean))) As System.Linq.IQueryable(Of Common.Model.Product) Implements Common.Repository.IReadOnlyRepository(Of Common.Repository.IProductRepository, Common.Model.Product).Where
Return CurrentObjectSet.Where(predicate)
End Function
Public Sub DeleteOnSubmit(ByVal entity As Common.Model.Product) Implements Common.Repository.IRepository(Of Common.Repository.IProductRepository, Common.Model.Product).DeleteOnSubmit
CurrentObjectSet.DeleteObject(entity)
End Sub
Public Sub InsertOnSubmit(ByVal entity As Common.Model.Product) Implements Common.Repository.IRepository(Of Common.Repository.IProductRepository, Common.Model.Product).InsertOnSubmit
CurrentObjectSet.AddObject(entity)
End Sub
Public Sub UpdateOnSubmit(ByVal entity As Common.Model.Product) Implements Common.Repository.IRepository(Of Common.Repository.IProductRepository, Common.Model.Product).UpdateOnSubmit
CurrentObjectSet.Attach(entity)
Context.ObjectStateManager.ChangeObjectState(entity, EntityState.Modified)
End Sub
Public Sub SubmitChanges() Implements Common.Repository.IRepository(Of Common.Repository.IProductRepository, Common.Model.Product).SubmitChanges
SaveChanges()
End Sub
End Class
End Namespace
La mia applicazione al momento è composta da 3 progetti:
Nel link sottostante potete vedere la struttura della soluzione.
http://85.39.202.194/MiaSoluzione.gif A questo punto vorrei creare lo strato di presentazione dell'anagrafica prodotti tramite le webforms. Lo strato presentazione nella soluzione sopra postata dovrebbe coincidere con il progetto Demo1.
La singola pagina productslist.aspx (ad esempio) dovrebbe mostrare tramite una ListView l'elenco dei prodotti presenti, inserirli, modificarli ed eliminarli. Il tutto sfruttando le operazioni messe a disposizione dal repository sopra citato.
Leggevo un articolo di Dino Esposito che accennava alla creazione di un Service Layer posto fra l'UI e il Domain Layer.
A questo punto visto i miei dubbi e perplessità in merito, mi sarebbe di grande aiuto una vostra opione su quanto già fatto e su come procere per implementare l'IU appena richiesto.
Come sempre, vi ringrazio per la pazienza concessa!
Saluti
V.