unit-of-work

Register Generic Type with Autofac

陌路散爱 提交于 2019-11-26 19:50:22
问题 I have UnitofWork class and it implement IUnitOfWork. I try to register that with autofac : var builder = new ContainerBuilder(); builder .RegisterGeneric(typeof(UnitOfWork<Repository<>,>)) .As(typeof(IUnitOfWork)) .InstancePerDependency(); Implementation is: public class UnitOfWork<T, O> : IUnitOfWork where T : Repository<O> where O : BaseEntity { } public interface IUnitOfWork : IDisposable { void SaveChanges(); } Gives an error "Type expected" but this one work on another project: public

Why is PerThreadLifetimeManager used in this example?

我的梦境 提交于 2019-11-26 17:51:32
I am following the example linked to below for setting up unity to work with my service layer. My project is setup very similar to the one in this article and I understand everything except why exactly is PerThreadLifetimeManager used when registering the service dependency. Keep in mind I am also using a generic repository and unitofwork that is being used in my service layer as well. Most unity examples use the default(transient) lifetime manager, and since my setup is similar to the one below I'm wondering why I should use the PerThreadLifeimeManager? I am using an ASP.NET web forms project

Where to convert business model to view model?

依然范特西╮ 提交于 2019-11-26 15:55:38
问题 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

Entity Framework 6 Code First - Is Repository Implementation a Good One?

我的未来我决定 提交于 2019-11-26 11:46:17
问题 I am about to implement an Entity Framework 6 design with a repository and unit of work. There are so many articles around and I\'m not sure what the best advice is: For example I realy like the pattern implemented here: for the reasons suggested in the article here However, Tom Dykstra (Senior Programming Writer on Microsoft\'s Web Platform & Tools Content Team) suggests it should be done in another article: here I subscribe to Pluralsight , and it is implemented in a slightly different way

Looking for a Ninject scope that behaves like InRequestScope

二次信任 提交于 2019-11-26 08:37:19
问题 On my service layer I have injected an UnitOfWork and 2 repositories in the constructor. The Unit of Work and repository have an instance of a DbContext I want to share between the two of them. How can I do that with Ninject ? Which scope should be considered ? I am not in a web application so I can\'t use InRequestScope . I try to do something similar... and I am using DI however, I need my UoW to be Dispose d and created like this. using (IUnitOfWork uow = new UnitOfWorkFactory.Create()) {

Is UnitOfWork equals Transaction? Or it is more than that?

为君一笑 提交于 2019-11-26 08:35:54
问题 The internet is full of information about UnitOfWork pattern; even SO is not an exception. I still do not understand something about it. In my understanding UnitOfWork = Transaction in DB . Thats all; nothing more, nothing less. Is this correct? My confusion is due to how it is implemented in different ORM s. NHibernate uses ISession for more than just a Transaction . Dapper leaves everything to you. My question here is about design pattern only without considering any ORM or technology. If

How to implement Unit Of Work pattern with Dapper?

六眼飞鱼酱① 提交于 2019-11-26 07:45:42
Currently, I am trying to use Dapper ORM with Unit Of Work + Repository Pattern. I want to use Unit of Work as opposed to a simple dapper Repository due to the fact that my insert and updates require a degree of transaction processing. I have been unable to find any useful examples as most seem to use Entity Framework and have leakage issue within the Unit of Work. Could someone please point me in the right direction? This Git project is very helpful. I started from the same and did some changes as per my need. public sealed class DalSession : IDisposable { public DalSession() { _connection =

Is UnitOfWork and GenericRepository Pattern redundant In EF 4.1 code first?

僤鯓⒐⒋嵵緔 提交于 2019-11-26 07:29:36
问题 Wondering if I need to use the Genericrepository pattern and UnitOfWork to mock the repository.I am using MOQ.Is it now redundant since I have noticed that EF 4.1 has IDBSet. I have not figured out how to write something generic that usic IDBSet .If you have an example where you implement IDBSet can you show it to me? Any suggestions? 回答1: This is duplicate of many topics already discussed on SO but I agree that some of them can be hard to find because they are nested in other question What's

Dependency injection in unit of work pattern using repositories

混江龙づ霸主 提交于 2019-11-26 06:04:28
问题 I want to create a unit of work class that wraps around repositories in a similar way to this. The problem I\'m having is trying to implement dependency injection by replacing the generic repositories in the example with an IRepository interface. In the uow in the linked article they use getters to check if the repository is instantiated and if it isn\'t then instantiate it. public GenericRepository<Department> DepartmentRepository { get { if (this.departmentRepository == null) { this

When to use PerThreadLifetimeManager?

你说的曾经没有我的故事 提交于 2019-11-26 05:38:20
问题 I am following the example linked to below for setting up unity to work with my service layer. My project is setup very similar to the one in this article and I understand everything except why exactly is PerThreadLifetimeManager used when registering the service dependency. Keep in mind I am also using a generic repository and unitofwork that is being used in my service layer as well. Most unity examples use the default(transient) lifetime manager, and since my setup is similar to the one