unit-of-work

What is the correct way to use Unit of Work/Repositories within the business layer?

ぐ巨炮叔叔 提交于 2019-11-30 04:55:28
问题 Having built a small application using the Unit of Work/Repository pattern, I am struggling to understand how to use this properly within my business layer. My application has a a data access layer which can be either NHibernate or the Entity Framework. I can switch between these easily. I have a number of repositories, for example, Customer, Order etc. My unit of work will be either an ISession or an Object Context depending on which DAL I want to test with. My business layer contains a

Need a simple example of using nhibernate + unit of work + repository pattern + service layer + ninject

送分小仙女□ 提交于 2019-11-29 22:24:24
I am using nhibernate + fluent nhibernate asp.net mvc 3 ninject Currently I am using nhibernate, ninject with the repository pattern and service layers. So I have this ninject public class NhibernateSessionFactory { public ISessionFactory GetSessionFactory() { ISessionFactory fluentConfiguration = Fluently.Configure() .Database(MsSqlConfiguration.MsSql2008.ConnectionString(c => c.FromConnectionStringWithKey("ConnectionString"))) .Mappings(m => m.FluentMappings.AddFromAssemblyOf<Framework.Data.Mapping.TableAMap>().Conventions.Add(ForeignKey.EndsWith("Id"))) .ExposeConfiguration(cfg => cfg

Using DTO to transfer data between service layer and UI layer

感情迁移 提交于 2019-11-29 20:31:12
I've been trying to figure this out for days but there seems to be very little info on this particular subject with ASP.NET MVC. I've been Googling around for days and haven't really been able to figure anything out about this particular issue. I've got a 3 layer project. Business, DAL and UI/Web layer. In the DAL is dbcontext, repository and unit of work. In the business layer is a domain layer with all the interfaces and the EF models. In the business layer there is also a service layer with DTOs for the EF models and a generic repository service that accesses the repository. This picture

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

断了今生、忘了曾经 提交于 2019-11-29 20:11:33
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 development? Also if you work with multiple developers and if you don't want other developers to see your DAL

Unit of Work + Repository Pattern: The Fall of the Business Transaction Concept

孤者浪人 提交于 2019-11-29 18:56:49
Combining Unit of Work and Repository Pattern is something used fairly widely nowadays. As Martin Fowler says a purpose of using UoW is to form a Business Transaction while being ignorant of how repositories actually work (being persistent ignorant). I've reviewed many implementations; and ignoring specific details (concrete/abstract class, interface,...) they are more or less similar to what follows: public class RepositoryBase<T> { private UoW _uow; public RepositoryBase(UoW uow) // injecting UoW instance via constructor { _uow = uow; } public void Add(T entity) { // Add logic here } //

Appropriate lifecycle for repository classes using Castle Windsor

微笑、不失礼 提交于 2019-11-29 16:01:16
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 UnitOfWork to be a singleton, as a singleton instance could (for example) flush the changes made by several

Entity framework 6 providing repositories and UoW out of the box

匆匆过客 提交于 2019-11-29 15:26:51
问题 But how do you use it? I have a Code First project set up, and trying out some stuff with this new EF6. Reading all kinds of posts/blogs from at least 2 years old about EF4/5. But nothing whatsoever about EF6. Let's say I have these entities: public DbSet<Person> Persons { get; set; } public DbSet<Order> Orders { get; set; } public DbSet<Invoice> Invoices { get; set; } Do I still need to create repositories for each entity? Or would a class suffice with some methods to do some custom

Ninject Scope issue with Tasks/Threads

此生再无相见时 提交于 2019-11-29 13:59:05
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 to HttpContext. I've read about InThreadScope(), however I'm not sure how to implement it properly in my

Unit of Work with multiple Data Sources?

流过昼夜 提交于 2019-11-29 09:44:25
问题 It's possible (even probable) that I'm just not fully grokking the concept of a "unit of work." Basically, I see it as sort of a broad transaction used in an object-oriented environment. Start the unit of work, interact with the objects, commit or roll back. But how does this break down to the actual transactions on the data stores behind those objects? In a system with a single DB and an ORM (such as NHibernate) it's easy. The transaction can be maintained through the ORM. But what about a

ASP.NET MVC, Ninject, single instance per request for multiple constructors

随声附和 提交于 2019-11-29 06:11:46
问题 Im trying to implement an unit of work pattern by passing an unit of work instance into my repositories. Relevant code from Global.asax. public class SiteModule : NinjectModule { public override void Load() { Bind<IUnitOfWork>().To<SqlUnitOfWork>() .InRequestScope() .WithConstructorArgument("connectionString", ConfigurationManager.ConnectionStrings["Entities"].ConnectionString); Bind<IProductRepository>().To<ProductRepository>(); Bind<ICategoryRepository>().To<CategoryRepository>(); } }