c#,asp.net-mvc-5,asp.net-identity,structuremap,unit-of-work
after a lot analyzing and understand, I finally find the solution, first i have to inject the same context to avoid inject a new instance of the Context. the solution is: For<DbContext>().Use(()=>System.Web.HttpContext.Current.GetOwinContext().Get<ApplicationDbContext>()); before i was injecting and add a new instance of the DBContex. For<DbContext>().Use<ApplicationDbContext>(new ApplicationDbContext()); ...
c#,asp.net-mvc-4,repository-pattern,unit-of-work,business-logic
The short answer - it depends. If it's a fairly complex or sizable application, I like to create a service layer project with the repositories as dependencies. If it's a small application, I'll put the logic in the controller. In my opinion, if it takes more time and effort to...
asp.net-mvc,entity-framework,ef-code-first,unit-of-work,repositories
I've added a Repository layer on top of EF (which utilizes both Repository and UoW patterns inherently in its construction) in a couple of projects, and I've done that with one class that utilizes generics so that I only needed one file for all of my entities. You can decide...
asp.net-mvc-4,autofac,unit-of-work
Since you're using Autofac as your dependency resolver, you can get a reference to the implementation of IAuditService using: IAuditService audit = DependencyResolver.Current.GetService<IAuditService>(); Then call its methods: audit.Log(user.UserId, "Account", "Login", "Successfull login"); See DependencyResolver...
c#,entity-framework,dependency-injection,ninject,unit-of-work
Thats a choice that you have to made, it doesnt matter move all entities into another project. But in my case I always do it. If you have doubts, here an idea how to implement the GenericRepository How to use generic type with the database Context in EF6 Code First...
c#,asp.net,linq,entity-framework,unit-of-work
Use the overload of the SelectList constructor that takes a Value property name and Text property name: @Html.DropDownList("Empresa", new SelectList(empresas, "ID", "Name")) ...
I've implemented a setup that's quite similar to the ddd-cqrs-sample. There's a class for the "run environment" that's responsible for running commands with the corresponding command handlers. Besides this my RE implements the transaction boundary. It's responsible for starting a unit of work and do a commit/rollback after command execution...
c#,nhibernate,unit-of-work,tcpserver
You can attach to the session the detached object, see http://rmfusion.com/open_source/nhibernate/nhibernate_net_object_persistence.htm here said by reattaching the object to a new Persistent Manager (ISession). The object state will then be synchronized with the database again, at the end of the transaction. There are other orm such entity framework, but depend of...
entity-framework,design-patterns,repository,autofac,unit-of-work
The sense of the unit of work and the repository pattern is to describe exactly what is needed for example for a use case. So the unit of work which has repositories for every entity or can create a repository for any entity by a generic method is as much...
c#,entity-framework,inheritance,repository-pattern,unit-of-work
unitOfWork.FieldRepository has type IFieldRepository so only GetAllFields() is visible: IFieldRepository repository = unitOfWork.FieldRepository; repository.GetAllFields(); You need either cast it to EFGenericRepository<Field>, IFieldRepository (don't do it!) or add this method to the interface: public interface IFieldRepository { void Insert(Field entity); } Being virtual doesn't make any difference here, you can remove...
c#,asp.net-mvc-4,repository-pattern,unit-of-work,onion-architecture
Managing transactions in the repository is definitely not the standard way to do it, as it removes the possibility to implement business logic that spans multiple repositories (or multiple actions on the same repository) and is required to be executed atomically. I would try to keep the transaction management on...
asp.net-mvc,constructor,repository-pattern,unit-of-work,service-layer
Constructors in C# Given your code public TownService() : this(new UnitOfWork()) { //1 } public TownService(IUnitOfWork unitOfWork) { //2 _unitOfWork = unitOfWork; } Invoking new TownService() will Call the parameterless-constructor Instantiate a new UnitOfWork and call the overload TownService(IUnitOfWork unitOfWork), so //2 is executed. This happens because of the this(...)...
dispose,idisposable,unit-of-work
Found the answer changed to: Protected Overridable Overloads Sub Dispose(ByVal disposing As Boolean) If Not disposed Then If disposing Then context.Dispose() End If End If disposed = True End Sub Public Overloads Sub Dispose() Implements System.IDisposable.Dispose Dispose(True) GC.SuppressFinalize(Me) End Sub ...
c#,asp.net-mvc,asp.net-mvc-4,repository-pattern,unit-of-work
We saw together you should separate your service from your repository. Here, your problem seems to come from the fact you use two different dbcontext instances. one in your repository and one in your UnitOfWork. Instead, you should inject the same Dbcontext instance in your repository and your UnitOfWork. EDIT:...
c#,entity-framework,entity-framework-6,unit-of-work
Rewrite SkillTypeRepository to this: public class SkillTypeRepository : GenericRepository<SkillType>, ISkillTypeRepository { public SkillTypeRepository() : base(new SkillManagementEntities()) { } //rest of code etc } As mentioned in my comment, your SkillTypeRepository does not have a constructor, but the GenericRepository does, as the base class has a constructor you need to provide...
entity-framework,nhibernate,orm,repository-pattern,unit-of-work
Personally i think your approach is solid. But equally Im surprised you see this approach as very different to the repository / Unit of Work Pattern. Your IService layer is directly comparable to a basic Unit of Work layer combined with a repository layer implemented via an interface. The repository...
mobile,asp.net-web-api,breeze,repository-pattern,unit-of-work
1) No you cant use breeze contextProvider.SaveChanges() in your other controllers. contextProvider.SaveChanges(JObject saveBundle) breeze server side expects saveBundle to be a json data created by breeze client side js. 2) Create any other webapi controller for REST with its own repository. You can't work with breeze's repository saveChanges without breeze...
asp.net-mvc,design-patterns,ado.net,repository-pattern,unit-of-work
I've written a blog post which teaches you on how to write driver independent code and how to implement Uow/Repository pattern with plain ADO.NET. It's a bit too long to include in this answer, but basically the IDbtransaction will represent your Unit oF Work (or be contained in one) and...
entity-framework,dependency-injection,repository-pattern,autofac,unit-of-work
Your on the right track, I have used var mtc = new MultitenantContainer(container.Resolve<ITenantIdentificationStrategy>(), container); DependencyResolver.SetResolver(new AutofacDependencyResolver(mtc)); The identification strategy would be based on the logged in user. With defaults for when they aren't logged in. public class CompanyNameIdentificationStrategy : ITenantIdentificationStrategy { public bool TryIdentifyTenant(out object tenantId) { var context =...
From what I can gather you are trying to add entities with the same primary key, as you said in your example RowTo Add- 78,1,1 78,2,2 It doesn't look like your Add method is handling this correctly. You could first check if the entity exists by passing the primary key...
entity-framework,repository-pattern,unit-of-work
any .Include() calls should be added after the query is constructed, otherwise they are ignored. You should write public IQueryable<T> SearchFor(Expression<Func<T, bool>> predicate, string includePath = null) { var query = DbSet.Where(predicate); if (!string.IsNullOrEmpty(includePath)) { query = query.Include(includePath); } return query; } Your problem is also that you did DbSet.Include(includePath)...
c#,asp.net-mvc,repository-pattern,unit-of-work
I think I understand this better after some time, so figured I would close it. I didn't need to "override" anything, I just needed to add the additional work in my unit of work class (duh), and then call the insert. Thanks for the thought provoking responses.
php,model-view-controller,domain-driven-design,unit-of-work
Unit of Work control would typically be placed in the Application Service in DDD, so I guess that means option #2. Note though that your whole question might be due to an overcomplicated design. Too many Factories is generally a code smell -- especially the DomainFactory one :) Is there...
Generally you shouldn't even need UnitOfWork when you want only to retrieve data from database. UnitOfWork is more like transaction to db - you try to persist some set of data to db in one go - if everyfing goes ok it is saved, if not then everything is rollback....
c#,asp.net-mvc,entity-framework,unit-of-work
As another possibility, since you state you want each action to save automatically, you could do the save somewhere like here on ending the request: MVC End Request The pattern which does this (in one way or another) is actually called Unit of Work per request you can find more...
asp.net,asp.net-mvc,structuremap,unit-of-work,action-filter
The solution you found with suppressing caching in the FilterProvider is actually the same solution that the MVC integration libraries for both Autofac and Simple Injector use. But the caching behavior of attributes is just one of the many reasons why doing dependency injection in attributes is actually a bad...
c#,entity-framework,repository-pattern,asp.net-identity,unit-of-work
Found some sort of solution, which looks generic enough, but I'm still not sure if it's really good and doesn't break Repository/UnitOfWork pattern principles. I added generic GetDbContext() method to my IUnitOfWork: public interface IUnitOfWork : IDisposable { void Save(); IRepository<TEntity> GetRepository<TEntity>() where TEntity : class; TContext GetDbContext<TContext>() where TContext...
architecture,repository-pattern,unit-of-work
There is many concepts in your question that don't relate only to the technical part. I've been there trying to solve it technically but this always fails in the long run. What is important is also what a business expert have to say. This is where Domain Driven Design shines...
entity-framework,entity-framework-4,repository-pattern,unit-of-work
Yeah, don't use this anti pattern (generic repository wrapping DbContext while exposing EF entities). If you really want to use the Repository make the repository interface return ONLY business (or view models if it's a query repo) objects, never IQueryable or other details exposing EF or whatever are you using....
c#,asp.net-mvc,dependency-injection,unity,unit-of-work
I think your registration is overly complex. Just use a InjectionFactory to allow registering a delegate that creates the UnitOfWork class with its dependencies. Something like: container.RegisterType<IEntitiesUnitOfWork>( new PerRequestLifetimeManager(), new InjectionFactory(c => new UnitOfWork(new Entities(), UserProvider.AuthenticationData.User)); ...
c#,ef-code-first,entity-framework-6,unit-of-work
Thanks to SOfanatic's comment, the problem has solved now. I've updated my GenericRepository's BuildQuery method to reflect SOfanatic's suggestion and it worked. Here is the updated BuildQuery method: internal virtual IQueryable<TEntity> BuildQuery(Expression<Func<TEntity,bool>> filter = null, Func<IQueryable<TEntity>, IOrderedQueryable<TEntity>> orderBy = null, string includeProperties = "") { IQueryable<TEntity> query = this.context.IsReadOnly ?...
c#,inheritance,multiple-inheritance,idisposable,unit-of-work
You don't need to add it to the class declaration, unless you want to make it explicit for readability. However, what you may need, is to add a protected virtual void Dispose(bool disposing){ method override to perform the child class' clean up tasks if there are any. See here for...
asp.net-mvc,dependency-injection,repository-pattern,autofac,unit-of-work
Without looking at the view it is hard to say where your delay is. There are several things to consider: DI consume virtually no time here, so do not blame it When using ORMs, always pair it with a profiler like EF Profiler from Hibernating Rhinos or DevArt. See SQL...
c#,repository-pattern,unit-of-work
I wouldn't write the cancelling logic twice. Where you have it is up to you, but given your current structure, I'd inject ICustomerService into BatchService. So class could look something like public class BatchService : IBatchService { public ICustomerService<Customer> CustService { get; set; } public void CancelOrders(params int[] orderNos) {...
php,unit-testing,phpunit,unit-of-work
You don't need to mock constants, as basically mock objects extends the real objects and they have all of their constants. $unitOfWorkMock->expects($this->once()) ->method('getEntityState') ->will($this->returnValue($unitOfWorkMock::STATE_NEW)); ...