repository-pattern

FindBy Id method in EntityFramework

生来就可爱ヽ(ⅴ<●) 提交于 2019-12-13 01:41:43
问题 it is possible to implement FindBy method in Entity framework while we have this GenericRepository class : public class Repository<T> : IRepository<T> where T : class, IAggregateRoot { private readonly DbSet<T> _entitySet; public IQueryable<T> FindBy(Expression<Func<T, bool>> predicate) { //IQueryable<T> query=_entitySet. } } how can I Implement FindBy in this case !?? 回答1: My Repository has the following method to return a single entity by a given expression. public T FindSingle(Expression

Automapper missing type map configuration or unsupported mapping

时光总嘲笑我的痴心妄想 提交于 2019-12-12 21:25:04
问题 I have 2 class : Class 1 : (Domain) public class Book { public ObjectId Id { get; set; } public String ISBN { get; set; } public String Title { get; set; } public String Publisher { get; set; } public int? PageCount { get; set; } public Author Author { get; set; } } Class 2 : (Repository) public class Book { public ObjectId Id { get; set; } public String ISBN { get; set; } public String Title { get; set; } public String Publisher { get; set; } [BsonIgnoreIfNull] public int? PageCount { get;

How to force only one transaction within multiple DbContext classes?

可紊 提交于 2019-12-12 17:58:28
问题 Background: From another question here at SO I have a Winforms solution (Finance) with many projects (fixed projects for the solution). Now one of my customers asked me to "upgrade" the solution and add projects/modules that will come from another Winforms solution (HR). I really don't want to keep these projects as fixed projects on the existing finance solution. For that I'm trying to create plugins that will load GUI, business logic and the data layer all using MEF. Question: I have a

Generate repositories from EF Code First with created DbContext model classes

不问归期 提交于 2019-12-12 17:41:17
问题 I'm starting a new project and want to use EF Code First pattern but I also want to use the repository pattern. I have been looking for a way to generate the repositories from the dbcontext models but all answers I've seen so far are for generating repositories from .edmx or DB. I don't want to create an .edmx. The steps I want to do is this: 1. Write models 2. Generate repositories using t4 templates 3. Write app code from models and repos 4. Run Add-Migration to add migration code 5. Run

How to get User ID inside a separate assembly

别来无恙 提交于 2019-12-12 16:55:56
问题 I'm working on an application which has two projects: Core - houses the data access layer using repository pattern and domain-driven design UI - using ASP.Net MVC. Currently, I am able to get the current logged in user's info(id, name, etc..) inside the UI controller via the User property like this: using Microsoft.AspNet.Identity; public class ExamController : Controller { IExaminationRepository _repository; public ExamController() { _repository = RepositoryFactory.Get<IExaminationRepository

Is there with micronaut a way to have the “Spring Data JPA” repository autogenerated from an interface like in spring?

安稳与你 提交于 2019-12-12 16:28:56
问题 Im setting up a new micro service with micronaut and want it to access a database over jpa/hibernate. Is there an easy way to have the "Spring Data JPA" repositories implementation to be autogenerated from the interface like with spring? interface ExampleRepository { fun FindById(id: String): Example } Ideally i would the be able to import an ExampleRepository over DI into my service. EDIT: Micronaut Data is in the process of being released: https://github.com/micronaut-projects/micronaut

How to handle UseCase Interactor constructors that have too many dependency parameters in DDD w/ Clean Architecture?

微笑、不失礼 提交于 2019-12-12 13:18:54
问题 Using DDD w/ Clean Architecture, I'm instantiating all of my dependencies (e.g. Repositories and Services) first and injecting them into my UseCases. What I've noticed over time is that my list of dependencies for each UseCase has grown quite large over time. For example, my UseCase uses 3 Aggregate Roots so I have 3 repositories. Not so bad. But, as I add more features, I find myself adding Domain Services or more Repositories and having to inject them into the UseCase Constructor as well.

using ninject to inject dependency to The Model classes or non-controller classes

这一生的挚爱 提交于 2019-12-12 13:16:07
问题 I using Ninject 3 in Repository pattern in mvc 3 (steven sanderson Scaffolder). and in ninject i have the class "NinjectWebCommon" which in the "RegisterServices" method i resolved the dependencies and i think im ready to go. private static void RegisterServices(IKernel kernel) { kernel.Bind<ICityRepository>().To<CityRepository>(); kernel.Bind<IVillageRepository >().To<VillageRepository>(); } i using my repositories in controllers using constructor injection and everything is fine. public

DI and repository pattern

为君一笑 提交于 2019-12-12 12:26:17
问题 Currently, my code is similar to this (shortened just to make a point): DAL Repository Interface public interface IRepository<TEntity, in TKey> { IList<TEntity> GetAll(); TEntity Get(TKey id); TEntity Add(TEntity item); TEntity Update(TEntity item); bool Remove(TKey id); } Base EF repository public class BaseEFRepository<TEntity, TKey> : IRepository<TEntity, TKey> where TEntity: class, IEntity<TKey> where TKey: struct { protected readonly DbContext _dbContext; public BaseRepository() {

Repository Pattern universal application

拟墨画扇 提交于 2019-12-12 10:18:54
问题 When I started learning Repository Pattern with Unity few days ago I was under impression that the main benefit of this pattern is the separation of data layer from the business layer. In other words, if there is a need to change the way, how application stores the data, it's very easy as only one main model takes care of the communication. This means, that if application currently saves data into a serialized XML files, it would not be very difficult to change this logic to connect to