New Feature Development Guide
This document guides you to adding new features. Just follow questions and instructions which fits to your situation. Please DO NOT ADD ANY FILE WITHOUT READING THIS GUIDE!
Let's start with finding your commitment type:
My new feature requires...
Database Changes
All database changes requires DbContext changes and will be applied to database with Entity Framework Migrations.
Adding new table
Firstly you need to create model of your new table in
Models.EntityFramework
namespace.Then find TenantDbContext or CoreDbContext in
Contexts.EntityFramework
namespace which is related with you feature.Add
DbSet<YourType>
as virtual property.Find
OnModelCreating()
method and define your model's standards.
See here to learn how to do.Create a Migration class which inherits from Migration in
Contexts/EntityFramework/Migrations/
folder.Define your requirements into Migration. You MUST define both of
Up
andDown
methods. See here to read more about migrations.Now you can use Migrate() method in Startup like that:
// This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
public void Configure(IApplicationBuilder app, IHostingEnvironment env, CoreDbContext coreDbContext)
{
coreDbContext.Database.EnsureCreated();
coreDbContext.Database.Migrate(); // <-- This will be apply your migration into database when application is started after deployment.
}
Modifying a table
To be added...
Deleting a table
To be added...
Repository Changes
Adding new Repository
Abstraction
Think About Abstration First!
First step is abstraction of your new repository. So, create an interface in
Applyze.Identity.Interfaces
namespace.Let say your model is MyType from now, this document will use MyType while talking about your new feature's model.
Don't you have a model? Go this step then come here back.Interface name must start with
I
as .Net Default and must end withRepository
. For Example IMyTypeRepositoryYour interface must inherit from
BaseRepository<T>
. Of yourceT
is your Entity Type (MyType as sample)
public interface IMyTypeRepository : IBaseRepository<MyType>
{
/*
Place here your custom methods except CRUD.
CRUD comes from IBaseRepository
*/
}
Concrete
If you completed Abstraction step, you're ready following steps.
Find
Repositories
folder and you'll see EntityFramework folder. If your implementation will be with Entity Framework yeah that's right right place to create your repository class.
I want to use another implementation instead of Entity Framework: Click hereYour Repository name must contain implementation type and must end with
Repository
. Pattern is{Type}{Provider}Repository
. For example: MyTypeEntityFrameworkRepositoryThen your class must inherit from
BaseEntityFrameworkRepository
. It already has implementation of CRUD processes, you'll need to apply implementation of only your custom methods.Add one more inheritence from your Abstraction interface now:
public class MyTypeEntityFrameworkRepository : BaseEntityFrameworkRepository<MyType, TenantDbContext>, IMyTypeRepository
{
/* Do your custom methods implementation here. */
}
- Finally, do not forget register your implementation to DI Container. Go Startup.cs and add your service
AddTransient
,AddScoped
orAddSingleton
.
services.AddTransient<IMyTypeRepository, MyTypeEntityFrameworkRepository>();
- You're ready! You can go Controller Changes Step now! 🎉
External Services
To be added...
Controller Changes
To be added...