dependency injection - ASP.Net MVC 3 - unitOfWork.Commit() not saving anything -


I have created a web application using ASP.Net MVC 3 and EF 4.1, and I am using UnitOfWork pattern I am nothing but there is nothing in the database, it is all new for me, and I do not know where to start this issue.

I am based on this post to create my web application:

The last code, which can be obtained, also has a service layer And the unitofwork is being injected into the services.

Instead of using custom injectors based on Unity 2, I am using Unity, project. MVC3

Here's my IUnitOfWork class:

  Public Interface IUnitOfWork {void Commit (); }   

And here is my unit affiliate class:

  Public class UnitOfWork: IUnitOfWork {Private Readonly Database Database Database Factory; Private MyProjectContext Datacontex; Public UnitOffArt (IDBase Database DatabaseFinary) {this.databaseFactory = databaseFactory; } Protected MyProjectContext DataContext {get {return dataContext ??} (Datacontax = DatabaseFeatureGet ()); }} Public Zero Commit () {DataContext.Commit (); }}   

And here's how one of my service classes looks like:

  Public Sector Area Service: IRegionService {Private Reddone IRegionRepository RegionRepository; Private Readonly IUnitOfWork unitOfWork; Public Sector Service (IRegionRepository Area Repository, IUnitOfWork unitOfWork) {this.regionRepository = regionRepository; This.unitOfWork = unitOfWork; } ...}   

On start-up, my unitofwork component is being registered as:

  Container. Registration Type & lt; IUnitOfWork, UnitOfWork & gt; ();   

Now, whether I try to insert, update or delete, no request is being sent to the database. What is missing here?

UPDATE :

Here is the content of the data content. Comet ():

  Public category MyProjectContext: DbContext {public DbSet & lt; Region & gt; Area {get; Set; } Public Virtual Zero Commit () {base.SaveChanges (); }}   

And here is the database feature. Gate ():

  Public Interface IDBasefactor: IDisposable {Get MyProjectContext (); }  UPDATE # 2:   

Using the debugger, I see that when my service service and controller controllers have a bar There are only one selection to work, but when updating, they are called twice, is this normal?

OK, I found the culprit. With this I am registering my database factory.

Instead

  container. Registration Type & lt; IdatabaseFactory, DatabaseFactory & gt; ();   

I want

  container Registration Type & lt; IdatabaseFactory, DatabaseFactory & gt; (New hierarchical Lifetime Manager ());   

I found information on this website:



Comments

Popular posts from this blog

mysql - BLOB/TEXT column 'value' used in key specification without a key length -

c# - Using Vici cool Storage with monodroid -

python - referencing a variable in another function? -