ASP.NET Boilerplate project structure for new entities/services - asp.net-core

I have started to play around with ASP.NET Boilerplate framework. I want to keep my application-specific entities and services in two separate projects. This will keep the core framework project untouched.
However I am not sure if i have the entities in a separate project how will the migrations work. The module system in the documentation touches about the logic piece, but it does not talk about entities that are local to the module (so each module has its own entity that gets created when migrations take place).
What options do we have if we need to separate our entities and services to individual projects?

However I am not sure if i have the entities in a separate project how will the migrations work.
Migrations work based on the DbSet that you define for each entity in DbContext.
What options do we have if we need to separate our entities and services to individual projects?
So you can have the entities in a separate project.
Add a dependency on YourSeparateCoreModule to *EntityFrameworkModule:
[DependsOn(
typeof(AbpProjectNameCoreModule),
typeof(YourSeparateCoreModule), // Add this
typeof(AbpZeroCoreEntityFrameworkCoreModule))]
public class AbpProjectNameEntityFrameworkModule : AbpModule
Then add a DbSet for each of the entities.

Related

Initializing UserManager<TUser> in class library project

I have an ASP.NET Core 5.0 MVC application and a .NET 5.0 class library called Application.Data. Due to separation of concerns, I decided that the DbContext and migrations should be contained within the data library. The DDL migrations work perfectly, but I'm having issues seeding AspNetCore.Identity users from within the data library.
Simply put, I want to access a UserManager<MyUser> instance in order to invoke the CreateAsync/AddToRoleAsync methods, but the UserManager constructor takes eight parameters that then also need to be instantiated. My understanding is that I could inject the user manager using the AddIdentity method to the service collection of my MVC project, but since my DbContext is contained within Application.Data, I wouldn't be able to run migration commands from within the MVC project.
What is the best course of action here?

Project structure for microservices

One of the project I am working the project architect is saying that we should make each layer as a separate maven project for e.g. For entity beans there is one maven project for dao interfaces separate project dao impl there is another project service interface there is one project service impl there is another project and controller is another project. In controller we are adding entity, dao and service project as dependency. Is it the right structure? What are the drawbacks and benefits of this structure? What should be the right way to micro services project structure?
We have 9 microservices so there are almost 40 projects. It feels clumsy.
you need to make separate projects for things which are consumed directly by other microservices like Beans. For eg: and things which are part of microservice impl.
Why we need to make separate:
Service A has 5 Beans which are exposed on using API IServiceAAPI
Now Service B use Service A by using API IServiceAAPI(assuming your framework automatically create a IServiceAAPI Object which calls the actual service) and return one of the beans. So either you rewrite those beans of use the original API from Service A, as it helps when the API changes your code automatically get the updates.
In general it makes sense that you have one project named ServiceAAPI which contains API, Beans and other project named ServiceAImpl

Using Identity DbContext and DbContext in a class library in ASP.NET Core

I have a .NET Core 2.0 solution which contains a class library project and an ASP.NET MVC project. The MVC project reference the class library. Class library has all the entity classes and DbContext using EF Core. Everything was fine up to that.
Then I added ASP.NET Identity to the MVC project. It creates a separate IdentityDbContext to create the identity-related entities. I want relationships (foreign keys) between the Identity user entity and some of my other entities (I am using code first migrations). And I don't want to do migrations twice from both DbContextes. What is the correct approach to use here?
Combine your two contexts into one. In other words, just make your original context inherit from IdentityDbContext, instead of DbContext and dump the one the Identity scaffold created for you.

Multiple SVC references each exposing same entities

I have a WPF application that uses a WCF services to perform operations on entities using EF4.
My project structure is as follows:
Project: EntityObjects
this is where the edmx file lives
Project: WCFService
References EntityObjects
Has data contracts to perform actions on entities
Has three different svc files, called Partner.svc, Section.svc, Scheme.svc
Project: DataLayer
has service references to Partner.svc, section.svc, scheme.svc
The problem is that the DataLayer project then has ambiguous references to objects as each svc file returns its own references of the entity objects.
How do I get around this?
It will not work this way. If you want to have same data contract types among all three service references you must use data contract sharing. That means that your data contracts must be provided to client project in separate assembly prior to adding service references. Most often this means that you will share data contract assembly between server and client. In your case it means sharing EntityObjects with whole EF stuff - that is bad.
There are multiple solutions:
Placing entities and EDMX stuff into separate projects and share only project with entities
Use custom Data transfer objects instead of entities as data contracts and share assembly with these DTO
Don't share assembly and instead create "copy" of data contracts manually for client
Don't expose same entities through different services
Use only single service if it makes sense in your architecture
Last two choices are more about architecture of your application.
You could :
Build a wrapper class that wrapped access to all 3 services. Then reference the objects concerned in the DataLayer project directly rather than through the service and convert as required in the wrapper class.

wcf and ADO entity framework

We are using Linq to Entities in WCF service. We created a edmx file which contains auto generated entities. While creating proxy the entities are not appearing in the proxy class even the data contract and datamember attributes are there. We found that the problem is because of the auto generated entities are inheriting from something called System.Data.Objects.DataClasses.EntityObject But if we create a class without any inheritance that class is appearing in the proxy. Is there any way to resolve this?
Regards
Sekar
The way we do this is:
Auto generate entity framework entities
Create separate classes to be used in the data contracts
Write mapping code to convert from one contract classes to entity classes, and back
This may be a bit cumbersom but it works (it also isolates your services from changes in your database). This should become much easier in the next version of entity framework.