unit-of-work

Unit of work pattern

独自空忆成欢 提交于 2019-12-06 04:48:51
问题 I'm looking for some advices about the unit of work pattern. Is the commit on the unit of work called multiple times or just one time and then leaving the object for garbage collection? Is it a good idea to inject the unit of work play or should I pass it around in method call when asking objects to perform some work? 回答1: Instances of types that implement the unit of work pattern usually have a single owner that needs to control its lifetime. Methods like Commit , Open , Close , and Dispose

Repositories and Units of Work - which is responsible for what?

孤者浪人 提交于 2019-12-06 02:55:08
问题 Over the past week or so I have been reading a lot of articles and tutorials regarding the repository pattern. A lot of the articles closely tie the repository pattern to the unit of work pattern. In these articles, I usually find code similar to this: interface IUnitOfWork<TEntity> { void RegisterNew(TEntity entity); void RegisterDirty(TEntity entity); void RegisterDeleted(TEntity entity); void Commit(); void Rollback(); } interface IRepository<TKey, TEntity> { TEntity FindById(TKey id);

Using a Custom Endpoint Behavior with WCF and Autofac

拟墨画扇 提交于 2019-12-06 02:31:06
问题 I'm trying to implement a UoW like shown here: http://blog.iannelson.systems/wcf-global-exception-handling/ But I can't for the life of me figure out how to wire it up with Autofac. I have absolutely no idea where to start. I've got WCF working fine with Autofac from using http://autofac.readthedocs.org/en/latest/integration/wcf.html But to inject or add the IEndpointBehavior? No idea... If there's a better way to implement a UoW I would like to hear. Edit: For now I've just done: builder

Repository + UnitOfWork pattern for entity framework

烈酒焚心 提交于 2019-12-05 21:56:52
问题 I was searching the net up and down and I didn't manage to find a suitable design for my application. I am looking for Repository+UnitOfWork pattern that will manage connections and dispose them automatically when done. I need to support both web application where each request will have its own UnitOfWork and windows application where each thread will have its own UnitOfWork. I need the patters to dispose automatically the UnitOfWork whrn request/thread is done. I also would like to support

How to get id from Add using UnitOfWork pattern?

血红的双手。 提交于 2019-12-05 20:16:09
I am using the UnitOfWork pattern to abstract database access in my Asp.Net application. Basically I follow the UnitOfWork pattern approach described here: https://chsakell.com/2015/02/15/asp-net-mvc-solution-architecture-best-practices/ However, I'm struggling to understand, how I will get the Id of a newly added item. Like if I want to add a new customer to my Customer repository, how will I get the customer id? The problem is that Add and Commit are decoupled, and the Id is not known until after Commit. Is there a way to get the id of an added item, using the UnitOfWork pattern? Note that I

IUnitOfWork how to use - best practice

倾然丶 夕夏残阳落幕 提交于 2019-12-05 17:51:34
I'm using EF4.3.1 in a .Net4.0 web forms (not MVC!) application. I tend to use the repository pattern with an IUnitOfWork interface. But I'm wondering if I'm following best practices, especially since most examples I've followed are based on MVC apps. I will say it's only a small web app, so that may affect the solution choices. The solution currently has 3 projects, Model, Logic and Site. Model contains the codefirst entities and the IUnitOfWork interface. Logic contains the repositories and service layer. Site obviously contains the website, codebehind, etc. I don't use any third-party

Managing Transactions either in service layer or repository layer?

此生再无相见时 提交于 2019-12-05 17:15:18
I have a certain scenario where inserts and updates are done on multiple tables based on some constraints ..so its natural to use Transaction scope for these scenarios.Now,I have a respository layer and a service layer. service layer mediates the repository and the UI and is persistent ignorant. Now i m confused where to use the transactions either in service or in repository layers.I am not using any ORMs. I have also seen people advocating about Unit of work pattern for such scenarios. are there any examples about unit of work pattern that suits my current scenarios,all the examples i have

Unity framework - reusing instance

不羁岁月 提交于 2019-12-05 09:45:09
nobody loved my first question about this: Creating Entity Framework objects with Unity for Unit of Work/Repository pattern so I've managed to rephrase it to something you can read without falling asleep/losing the will to live. I'm creating an object, DataAccessLayer, that takes 2 interfaces in the constructor: IUnitOfWork, and IRealtimeRepository: public DataAccessLayer(IUnitOfWork unitOfWork, IRealtimeRepository realTimeRepository) { this.unitOfWork = unitOfWork; this.realTimeRepository = realTimeRepository; } Now, the constructor for the implementation of IRealtimeRepository also takes an

Is the Entity Framework 4 “Unit of Work” pattern the way to go for generic repositories?

爱⌒轻易说出口 提交于 2019-12-05 09:41:41
问题 I am looking into creating an Entity Framework 4 generic repository for a new ASP.NET MVC project i am working on. I have been looking at various tutorials and they all seem to use the Unit of Work pattern ... From what i have been reading, EF is using this already within the ObjectContext and you are simply extending this to make your own Units of Work. Source: http://dotnet.dzone.com/news/using-unit-work-pattern-entity?utm_source=feedburner&utm_medium=feed&utm_campaign=Feed%3A+zones

Multiple database contexts when using repository pattern

谁说胖子不能爱 提交于 2019-12-05 08:31:46
问题 I am a bit lost right now... I've never seen this much divergent information regarding solution to the problem. But let us start from the beginning. I am using ASP.NET MVC with Repositories injected to Controllers, thanks to the Ninject. I have 2 simple Entities: Admin with a list of created blog entries and Entries with one virtual Admin field. Admin: public class Admin { [Key, ScaffoldColumn(false)] public int Id { get; set; } [Required(ErrorMessage = "Zły login.")] [StringLength(20),