Repository
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.
The Repository is the interface through which FwkLight manages the database related tasks for one aggregate (save, load, etc).
It works only with individual aggregates, not with lists of aggregates. When you need to load a list of aggregates, you should always use a Query (instead of a Repository).
When saving aggregates, it automatically uses the current UnitOfWork (you don’t have to manage that manually).
The repository uses an IMultiCriteriaFetcher<EntityType> (which can be accessed through the MultiCriteriaFetcher property) to do most of its work.
It is automatically instantiated in any BaseLoadTask or BaseSaveTask service, and you don’t need to use it directly. You will only use the IMultiCriteriaFetcher<EntityType> that it offers, so you can configure the necessary filters.
In the following example, the LoadTask configures its internal Repository by overriding the ConfigureFilters method:
public class SomeEntityLoadTask: BaseLoadTask<SomeEntity> { private string _filter; public SomeEntityLoadTask(IBaseRepo<SomeEntity> repository, INHUnitOfWorkProvider uowProvider) : base(repository, uowProvider) { } public SomeEntity Execute(string filter) { _filter = filter; ExecuteInternal(); return Entity; } protected override void ConfigureFilters() { Fetcher.Where(p => p.SomeEntityContent).Eq(_filter); } }
About this entry
You’re currently reading “Repository,” an entry on The FwkLight blog
- Published:
- April 24, 2010 / 11:07 am
- Category:
- Uncategorized
- Tags:
No comments yet
Jump to comment form | comment rss [?] | trackback uri [?]