- UnitOfWork pattern Øviv set of task ‡K single group of transactional work G grouping K‡i|
- UnitOfWork pattern use K‡i Entity Framework data contex ‡K multiple managers and repositories gva¨‡g sharing Kiv hvq|
- UnitOfWork pattern use K‡i multiple code blocks, methods, classes, repositories ‡K single database transaction AvKv‡i execute Kiv‡bv nq|
UML Diagram:
·
Business transaction Gi mgq hvnv wKQz database G
affect K‡i Unit of Work mKj wKQzi track iv‡L Ges †mB Abyhvqx database G
cwieZ©b K‡i|
Code Example:
- cÖ_‡g Avgiv interface create Kwi IUnitOfWork bv‡g hvi definition wb¤œiƒc-
namespace CodeFirstData.DBInteractions
{
public interface
IUnitOfWork
{
void Commit();
}
}
- IUnitOfWork interface‡K implement K‡i Avgiv GKwU concrete class create Ki‡ev hvi definition wb¤œiƒc-
namespace CodeFirstData.DBInteractions
{
public class UnitOfWork : IUnitOfWork
{
private readonly IDBFactory _databaseFactory;
private CodeFirstContext _dataContext;
public UnitOfWork(IDBFactory databaseFactory)
{
this._databaseFactory = databaseFactory;
}
protected CodeFirstContext DataContext
{
get { return _dataContext ?? (_dataContext =
_databaseFactory.Get()); }
}
public void Commit()
{
DataContext.Commit();
}
}
}
কোন মন্তব্য নেই:
একটি মন্তব্য পোস্ট করুন