unit-of-work

Is Unit Of Work and Repository Patterns very useful for big projects?

感情迁移 提交于 2019-11-28 16:00:54
问题 I'm starting a new web project using ASP.NET Webforms + EF4. I'm trying to apply a repository pattern with a unit of work pattern following this tutorial : http://www.dotnetage.com/publishing/home/2011/07/05/6883/the-repository-pattern-with-ef-code-first-dependeny-injection-in-asp-net-mvc3.html I think I got the idea but my question is that, when I create a new object in the model, do I also have to define that object in IDALContext of the Unit Of Work? Isn't that a handbreak for rapid

What is the point of the Update function in the Repository EF pattern?

ⅰ亾dé卋堺 提交于 2019-11-28 11:36:39
问题 I am using the repository pattern within EF using an Update function I found online public class Repository<T> : IRepository<T> where T : class { public virtual void Update(T entity) { var entry = this.context.Entry(entity); this.dbset.Attach(entity); entry.State = System.Data.Entity.EntityState.Modified; } } I then use it within a DeviceService like so: public void UpdateDevice(Device device) { this.serviceCollection.Update(device); this.uow.Save(); } I have realise that what this actually

Appropriate lifecycle for repository classes using Castle Windsor

ぐ巨炮叔叔 提交于 2019-11-28 10:17:51
问题 When I started with Windsor I thought DI would be simple. Now it's causing me more and more confusion. A repository strikes me as a class with a singleton lifecycle. I should have a single instance of a FooRepository to load and save Foos to the database during the application's lifetime. However, each repository holds a reference to a UnitOfWork, which does the dirty checking, works with the database etc. The UnitOfWork has a lifecycle of PerWebRequest - it makes no sense at all for the

Ninject Scope issue with Tasks/Threads

旧时模样 提交于 2019-11-28 07:27:45
问题 I have an MVC3 project that uses Ninject, Entity Framework and the Unit of Work pattern with a Service layer. My AsyncService class has a function that starts a background task that, as an example, adds users to the User repository. My current problem is that the task only runs correctly for a few seconds before I get an error that the DbContext has been disposed. My database context, which is injected with Ninject's InRequestScope() seems to be getting disposed, as InRequestScope() ties it

Using Unit of Work design pattern / NHibernate Sessions in an MVVM WPF

て烟熏妆下的殇ゞ 提交于 2019-11-28 06:59:57
I think I am stuck in the paralysis of analysis. Please help! I currently have a project that Uses NHibernate on SQLite Implements Repository and Unit of Work pattern: http://www.nhforge.org/wikis/patternsandpractices/nhibernate-and-the-unit-of-work-pattern.aspx MVVM strategy in a WPF app Unit of Work implementation in my case supports one NHibernate session at a time. I thought at the time that this makes sense; it hides inner workings of NHibernate session from ViewModel. Now, according to Oren Eini (Ayende): http://msdn.microsoft.com/en-us/magazine/ee819139.aspx He convinces the audience

Correct use of the NHibernate Unit Of Work pattern and Ninject

纵然是瞬间 提交于 2019-11-28 04:25:11
I have the following implementation and would like some feedback as to whether it makes correct use of NHibernate for sessions and transactions. public interface IUnitOfWork : IDisposable { ISession CurrentSession { get; } void Commit(); void Rollback(); } public class UnitOfWork : IUnitOfWork { private readonly ISessionFactory _sessionFactory; private readonly ITransaction _transaction; public UnitOfWork(ISessionFactory sessionFactory) { _sessionFactory = sessionFactory; CurrentSession = _sessionFactory.OpenSession(); _transaction = CurrentSession.BeginTransaction(); } public ISession

SQL Server : is there any performance penalty for wrapping a SELECT query in a transaction?

强颜欢笑 提交于 2019-11-28 02:19:11
As learning exercise and before trying to use any ORM (like EF) I want to build a personal project using ADO.NET and stored procedures. Because I don't want my code to become a mess over time, I want to use some patterns like the repository and UoW patterns. I've got almost everything figured it out, except for the transaction handling. To somehow 'simulate' a UoW, I used this class provided by @jgauffin, but what's stopping me from using that class is that every time you create a new instance of that class ( AdoNetUnitOfWork ) you're automatically beginning a transaction and there a lot of

Decouple unit of work from services or repo

拈花ヽ惹草 提交于 2019-11-27 18:54:05
I am trying to decouple my unit of work from my services or repository so that I wont have to touch the UoW code whenever I wish to add a new service. How do I do this? _categoryService = _unitOfWork.Get<ICategoryService>(); so instead of _unitOfWork.CategoryService.Add(category) I can just say; _categoryService.Add(category); I am trying to decouple my unit of work from my services or repository so that I won’t have to touch the UoW code whenever I wish to add a new service Well, that’s a good start! ;-) The solution I am presenting is not the one and only possible solution, there are several

How to implement Unit of Work that works with EF and NHibernate

允我心安 提交于 2019-11-27 12:11:28
I was working on a Unit of Work implementation that works both in Entity Framework 4.1 and NHibernate. Find below the skeleton of my implementation details IUnitOfWork definition public interface IUnitOfWork { IRepository<LogInfo> LogInfos { get; } IRepository<AppInfo> AppInfos { get; } void Commit(); void Rollback(); } IRepository definition public interface IRepository<T> where T : class, IEntity { IQueryable<T> FindAll(); IQueryable<T> FindWhere(Expression<Func<T, bool>> predicate); T FindById(int id); void Add(T newEntity); void Remove(T entity); } Implementation of UoW in NHibernate

Where to convert business model to view model?

≯℡__Kan透↙ 提交于 2019-11-27 12:10:53
In my ASP.NET MVC application, I am using unit of work and repository patterns for data access. Using the unit of work class and the repository defined inside it I am fetching the related set of entities in my controller. With my beginner knowledge, I can think of two ways to fetch the business model and convert it to view model. Repository returns the business model to controller, this model than mapped to view model, or Repository itself converts business model to view model and then it is returned to controller. Currently I am using first approach, but my controller code started to look