Questions tagged [unit-of-work]
The unit-of-work tag has no usage guidance.
46 questions
4
votes
2
answers
986
views
Is the entire web request the right scope for a DbContext in EF Core?
The usual advice for using EF Core in a web application is to use a scoped DbContext per HTTP request. This is even the suggested default for web application in the Microsoft documentation. I recently ...
2
votes
1
answer
265
views
two diffrent database in unit of work
I will explain my problem in the form of an example.
Suppose we want to use both databases in a transaction.
Data is edited in database 1 (for example, Postgres) and then added to database 2. Finally, ...
1
vote
2
answers
376
views
Using multiple databases in a bounded context
Sometimes we have to use multiple databases in one project
with the intentions of:
Denormalizing data or read models
Using the advantages of that database (technology)
There has been a lot of talk ...
0
votes
0
answers
254
views
Implementing the Repository/UnitOfWork pattern using Azure.Data.Tables "TableClient"
I currently have a generic Azure repository AzureRepository<TEntity> store internally a list of table transaction actions like so.
private readonly IList<TableTransactionAction> ...
0
votes
1
answer
3k
views
Where to put SaveChanges in unit of work?
For the sake of discussion, you can assume I'm using Entity Framework and a mediator pattern implementation in .NET.
I'm going back and forth trying to decide how to structure some of my data access ...
6
votes
3
answers
14k
views
Is unit of work pattern really needed with repository pattern
I am trying to use EF6 with my project. I just watched Repository Pattern with C# and Entity Framework, Done Right | Mosh video. I understand the necessity of Repositories but I still don't understand ...
8
votes
2
answers
8k
views
Avoiding Repository pattern - implementing Onion Architecture with DbContext only
I am trying to follow the Onion Architecture to design my application where I have the following layers -
Domain Layer: is the inner-most layer and defines repository interfaces
Infrastructure ...
0
votes
2
answers
3k
views
c# Manage more Repository in UnitOfWork
I have a question about how can manage multiple repositories with unit of work.
I thought for two solutions but I'm not sure.
The first is a classic solution where the IUnitOfWork interface looks like ...
3
votes
1
answer
844
views
Saga vs. Unit of work
What's the relationship between the two?
Both are for atomic operations. Both results need to be either success, or failure with rollback to original state.
-1
votes
1
answer
3k
views
Update Entity for Repository Pattern and UOW Pattern C#
In one mock solution, I have created 3 mock projects to implement layered architecture design mainly the - Presentation Layer (Web) - Domain Model Layer - Infrastructure Layer. I haven't yet to add ...
1
vote
2
answers
1k
views
How to get ORM (Ef Core) Entities follow a DDD style . Which is the best approach?
I am considering mutliple options to face a problem.
I want to develop software following DDD style.
The problem arise when I have to define my entities and I am working with Entity Framework Core, ...
1
vote
3
answers
722
views
Tracking state on entity and unit-of-work pattern
In my web app I have a long running operation that is processing some entity in the background. The state of this process should be visible to the clients. During the processing the UI should show ...
3
votes
2
answers
1k
views
Should a UnitOfWork contain every Repository?
I'm trying to get the Repository/UnitOfWork pattern figured out. We're working on a project with EntityFramework and our DBContext contains 200+ tables.
Right now our approach is to inject whatever ...
5
votes
2
answers
18k
views
Unit Of Work with multiple database context
I have created an application (net core 2 & ef core) with Unit Of Work and Generic repository pattern. I used to have one database context but due to some business logic I had to create a second ...
3
votes
2
answers
3k
views
Unit of work + repository pattern + dependency injection
I am in the process of refactoring and improving a codebase. One of the major missing features is transactional safety and certain errors arising from each repository having its own DbContext.
The ...
4
votes
1
answer
1k
views
Should unit of work create repository?
Our "unit of work" class has a method which takes a class type and creates a repository:
public IRepository<TEntity> GetRepository<TEntity>() where TEntity : class
{
...
1
vote
0
answers
3k
views
Proper implementation of Repository Pattern with MVVM in WPF
I am currently refactoring a WPF application that is built on the principles of the Repository Pattern. It uses Entity Framework as its ORM, and is Database First. Each of those entities is wrapped by ...
1
vote
0
answers
794
views
Putting UnitofWork handler in the Request Model for DDD with Clean architecture?
I'm rearchitecting a system in Python, using SQLAlchemy for the data mapping layer, and the Zope Component Architecture for dependency injection and interface declaration. I am in the process of ...
1
vote
1
answer
1k
views
Making UnitOfWork testable
I'm in the process of refactoring legacy code. Unfortunately it is a WebForms application with very tight coupling and smelly code. Currently access to database is inside models which looks something ...
0
votes
1
answer
1k
views
Do I need to use the Unit of Work pattern with a many to many relationship?
Please see the DDL below:
create table Person (ID identity not null, varchar(name), Gender char(1), dateofbirth datetime, primary key (id))
create table PersonOffer (PersonID int not null references ...
1
vote
2
answers
13k
views
Should I mock Repository and Unit Of Work for Unit Testing?
I have read this article: https://www.gaui.is/how-to-mock-the-datacontext-linq/
Since this article is almost 4 years old I have no hope that in article's comments my question will be answered so I ...
0
votes
2
answers
1k
views
Asp.Net Mvc 5 / Web Api 2 unit testing data access layer
Let's say I have IRepository interface implemented by Repository class(uses database context to implement IRepository methods). And IUnitOfWork interface implemented by UnitOfWork class using ...
5
votes
1
answer
6k
views
Is Unit of Work valid under a service pattern?
I've been studying design patterns. I've learned about Repositories, Unit Of Work, Dependency Injection, MVC. I'm now learning about Service Layer pattern.
I'm trying to grasp the utility purpose of ...
3
votes
1
answer
3k
views
Implementing unit-of-work for multiple storage types
I'm trying to implement the unit-of-work pattern for mutliple storage types like the windows registry, a database or the app.config but I cannot figure out how to do it. All examples I find use Entity ...
-1
votes
2
answers
1k
views
Best design pattern for two specific scenarios, the first one fits neatly into a Unit of Work(UoW) pattern
I have a question about what the best design pattern to use would be. I have 2 specific scenarios, the first one fits neatly into a Unit of Work(UoW) pattern. The second is a little bit more fiddly. ...
3
votes
1
answer
319
views
A "sort of" Units of Unit of Work
I've read Unit of Work pattern and tons of MVC/EF Unit of Work examples but what I'm trying to do is encapsulate multiple unit-of-work into a large set. Maybe this pattern already exists somewhere, ...
1
vote
0
answers
102
views
Can NHibernate's ISession be considered as implementation of unit of work pattern?
I am debating this with myself. Does NHibernate's ISession offer a proper and correct unit of work if used without a transaction? In absence of a transaction, every SQL command would be wrapped by the ...
7
votes
2
answers
1k
views
How to decide what forms the System Under Test
Ok, so we started with the initial version of "The Art Of Unit Testing" and we do unit tests for classes where every test covers one aspect of one method.
This has the drawback of high maintenance ...
0
votes
1
answer
344
views
Sharing core repository and object mapping logic between Unit of Work methods
I'm wondering if there is a better way to do this or if I'm doing some anti-pattern here. Like I say in the subject, I'm trying to share repository calls and object mapping logic between Unit of Work ...
1
vote
1
answer
599
views
How is the UnitOfWork pattern related to Monadic programming?
Looking over the definition of the Unit of Work pattern it seems very much like what a programmer would get if they implemented a Monad such as an IO or Transaction Monad. What makes the unit of work ...
1
vote
1
answer
3k
views
MockRepository vs Test Database for Unit Testing
Before starting, this question is not the same as this one.
Comming from a PHP background, my experience is in CakePHP, which is a framework that supports Unit Testing by setting up a local test ...
6
votes
1
answer
6k
views
Unit of Work Concurrency, how is it handled
I am reading some information about the Unit of Work pattern. There is one thing that is not very clear for me: what will happen when you request a couple of records on a thread (1) and another thread ...
0
votes
1
answer
264
views
How to save entities relations using unit of work pattern
I use Unit of work pattern to commit all new, dirty, deleted entities to the DB (using a db_mapper).
Example of entities are: Student and Class
So Student->registerDirty() will add this entity to ...
4
votes
2
answers
3k
views
Should I have separate units of work for each EF bounded context?
I have some EF bounded contexts like follows
public class BoundedContext_1 : DbContext
{
IDbSet<A> As { get; set; }
IDbSet<B> Bs { get; set; }
}
public class BoundedContext_2 : ...
4
votes
2
answers
638
views
Communication/Updates between units of works/entity framework contexts, colliding with user changes
I'm developing a WPF application using Entity Framework for my database communication. The application has a hierarchy of tabs where each tab has a db context. Each tab allows the user to view some ...
2
votes
1
answer
729
views
Would this be a correct way to use the Repository pattern in ASP .NET MVC application implementing Entity Framework?
This ASP .NET MVC application implements Entity Framework.
I've declared the repositories in the DbContext like this:
public class CompanyDbContext : DbContext
{
// constructor goes here
...
1
vote
1
answer
1k
views
Are there any concerns with using a static read-only unit of work so that it behaves like a cache?
Related question: How do I cache data that rarely changes?
I'm making an ASP.NET MVC4 application.
On every request the security details about the user will need to be checked with the area/...
6
votes
4
answers
2k
views
Unit of Work pattern
I have gone through many articles and I am still confused whether to use the Unit of Work pattern or not. I use generic repositories (Repository Pattern) but if my understanding of the UOW pattern is ...
2
votes
2
answers
6k
views
Unit of work/repository pattern with dependency injection advice
I'm developing a series of repository classes and a UnitOfWork class (plus its IUnitOfWork interface of course). I'm using Castle Windsor, which injects dependencies via constructors.
My business ...
243
votes
9
answers
166k
views
Why shouldn't I use the repository pattern with Entity Framework?
During a job interview, I was asked to explain why the repository pattern isn't a good pattern to work with ORMs like Entity Framework. Why is this the case?
3
votes
3
answers
3k
views
How to use the unit of work and repository patterns in a service oriented enviroment
I've created an application framework using the unit of work and repository patterns for it's data layer. Data consumer layers such as presentation depend on the data layer design. For example a CRUD ...
17
votes
2
answers
10k
views
Relationship between Repository and Unit of Work
I am going to implement a repository, and I would like to use the UOW pattern since the consumer of the repository could do several operations, and I want to commit them at once.
After read several ...
4
votes
3
answers
5k
views
Unit of work principle is causing a problem in MVC3 application
I am implementing a website using MVC3, Entity Framework 4.1 and Repositoty pattern, Unit of work principle. But I am facing a big problem while implementing this.
I have developed a static ...
1
vote
2
answers
2k
views
Why is the Unit of Work pattern considered fast and efficient when working with an ORM?
In working with Doctrine 2 I came across the following paragraph.
In fact, since Doctrine is aware of all your managed entities, when
you call theflush() method, it calculates an overall ...
8
votes
1
answer
7k
views
Hooking up a Business Layer and Repository using Unit of Work Pattern
My question is similar to this one on Stack Overflow: What is the correct way to use Unit of Work/Repositories within the business layer?
Scenario:
.Net solution
IRepository used to retrieve objects ...
6
votes
1
answer
133
views
Data services methods naming
When you work with ORM which implement UnitOfWork pattern (NHibernate's Session, Entity Framework's ObjectContext, etc.), there are two types of data services methods: those which save/commit changes ...