Unit of work
ALL THE EXAMPLES FROM THIS POST ARE EXTRACTED FROM THE FWKLIGHT DEMO. TO FIND OUT HOW TO GET STARTED WITH THE DEMO, READ THIS POST.
FwkLight contains a Unit Of Work implementation which is based on NHibernate. The Unit Of Work is managed automatically, so you don’t have to think about it at all.
What you need to know about the Unit Of Work when working with FwkLight is that it is an implementation of INHUnitOfWork, which has a property called Session of type ISession, which is the current NHibernate Session. Inside application tasks, you will need to get the current session from the current unit of work to initialize domain queries, so they can load data from the database.
In the following example, the ListQueryTask executes its query by sending the current Session (UOW.Session) as the first parameter:
public class SomeEntityListTask : BaseListQueryTask<SomeEntity> { private readonly SomeEntityListQuery _someEntityListQuery; private IList<int> _ids; public SomeEntityListTask(INHUnitOfWorkProvider uowProvider, SomeEntityListQuery someEntityListQuery) : base(uowProvider) { _someEntityListQuery = someEntityListQuery; } public IList<SomeEntity> Execute(IList<int> ids) { _ids = ids; ExecuteInternal(); return Entity; } protected override IList<SomeEntity> ExecuteQuery() { return _someEntityListQuery.Execute(UOW.Session, _ids); } }
About this entry
You’re currently reading “Unit of work,” an entry on The FwkLight blog
- Published:
- April 24, 2010 / 10:30 am
- Category:
- Uncategorized
- Tags:
No comments yet
Jump to comment form | comment rss [?] | trackback uri [?]