Skip to main content

Questions tagged [unit-of-work]

Filter by
Sorted by
Tagged with
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 ...
Mad Scientist's user avatar
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, ...
Amir Hosein's user avatar
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 ...
PersianMan's user avatar
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> ...
Reap's user avatar
  • 183
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 ...
Alexander Trauzzi's user avatar
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 ...
Mansur Ali Koroglu's user avatar
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 ...
atiyar's user avatar
  • 203
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 ...
pampua84's user avatar
  • 133
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.
Wei Huang's user avatar
  • 265
-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 ...
Steve's user avatar
  • 299
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, ...
X.Otano's user avatar
  • 622
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 ...
Dejan's user avatar
  • 119
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 ...
Winetradr's user avatar
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 ...
Dimitris's user avatar
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 ...
Flater's user avatar
  • 56.3k
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 { ...
Mediator's user avatar
  • 879
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 ...
Mycroft Holmes's user avatar
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 ...
Iain Duncan's user avatar
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 ...
FCin's user avatar
  • 522
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 ...
w0051977's user avatar
  • 7,129
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 ...
David Maisuradze's user avatar
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 ...
David Maisuradze's user avatar
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 ...
João Sequeira's user avatar
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 ...
t3chb0t's user avatar
  • 2,592
-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. ...
S-Unit's user avatar
  • 1,397
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, ...
Erik Philips's user avatar
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 ...
Suhas's user avatar
  • 297
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 ...
Ignacio Soler Garcia's user avatar
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 ...
programmer's user avatar
  • 3,388
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 ...
Kevin's user avatar
  • 31
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 ...
Christopher Francisco's user avatar
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 ...
Laurence's user avatar
  • 227
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 ...
Michael Ben-Nes's user avatar
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 : ...
Kamran's user avatar
  • 141
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 ...
Mårten's user avatar
  • 287
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 ...
Deniz's user avatar
  • 25
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/...
Rowan Freeman's user avatar
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 ...
Farax's user avatar
  • 161
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 ...
Andrew Stephens's user avatar
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?
StringBuilder's user avatar
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 ...
Amir Karimi's user avatar
  • 1,232
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 ...
NullOrEmpty's user avatar
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 ...
Pravin Patil's user avatar
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 ...
Peter Kelly's user avatar
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 ...
glosrob's user avatar
  • 245
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 ...
SiberianGuy's user avatar
  • 4,813