lundi 25 septembre 2017

Effect in application performance by Repository pattern and Unit of work with entity framework in asp.net mvc

I am working with a database where I have more than 75 tables and I am using repository pattern and unit of work with entity framework on asp.net mvc project. I am little bit confuse and some query in my mind about object creation. when unitofwork initialize, it create object for all table's entity which is present in unitofwork. so it can be heavy for application load.

Here is the interface of unit of work:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Application.Repository;
using Application.Repository.General;

namespace Application.UnitOfWorks
{
    public interface IUnitOfWork : IDisposable
    {
        IGeneralRegionMasterRepository GeneralRegionMasters { get; }
        IGeneralSubRegionMasterRepository GeneralSubRegionMasters { get; }
        IGeneralCountryMasterRepository GeneralCountryMasters { get; }
        IGeneralStateMasterRepository GeneralStateMasters { get; }
        IGeneralCityMasterRepository GeneralCityMasters { get; }



        int Complete();
    }
}

Implementation:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Application.EntityFramework;
using Application.Repository;
using Application.Repository.General;

namespace Application.UnitOfWorks
{
    public class UnitOfWork : IUnitOfWork
    {
        public readonly MSBMInventoryDbContext _context;
        public UnitOfWork(MSBMInventoryDbContext context)
        {
            _context = context;
            GeneralRegionMasters = new GeneralRegionMasterRepository(_context);
            GeneralSubRegionMasters = new GeneralSubRegionMasterRepository(_context);
            GeneralCountryMasters = new GeneralCountryMasterRepository(_context);
            GeneralStateMasters = new GeneralStateMasterRepository(_context);
            GeneralCityMasters = new GeneralCityMasterRepository(_context);
        }

        public IGeneralRegionMasterRepository GeneralRegionMasters { get; private set; }
        public IGeneralSubRegionMasterRepository GeneralSubRegionMasters { get; private set; }
        public IGeneralCountryMasterRepository GeneralCountryMasters { get; private set; }
        public IGeneralStateMasterRepository GeneralStateMasters { get; private set; }
        public IGeneralCityMasterRepository GeneralCityMasters { get; private set; }

        public int Complete()
        {
            return _context.SaveChanges();
        }

        public void Dispose()
        {
            _context.Dispose();
        }
    }
}

I want to know about performance effect of it on application. thank you in advance for help.

Aucun commentaire:

Enregistrer un commentaire