Reputation: 4549
I started a project using Asp.net core 2.1 and read several articles on the subject.
Asp.Net Core in the new architecture, as well as the previous, while using Razor pages, as in Asp.Net also allows you to write code to behind the page.
1- I think that the best place to inject dependency to the project is the controller classes. I didn't really understand what it would be like to write to code behind of the page in the new architecture. Also, if we look at optimizing usage, we should add re-dependency behind the page. What is logic
2- When I was dealing with the project, I realized that there is no relation between the Microsoft.AspNet.Identity.EntityFramework.IdentityDbContext class and the Microsoft.AspNetCore.Identity.EntityFrameworkCore.IdentityDbContext classes. If we want to upgrade any old Asp.Net project, is there any document related to architectural requirements with the reasons and best practices (as in the case of the DI mentioned above)
I don't have a problem with building the project, I'm just writing here to document this topic in order to better understand it and not to waste unnecessary effort.
Upvotes: 1
Views: 241
Reputation: 965
please right click on Area > add new Scaffold item I guess if you are using VS 2017 pro+ you might get a list of pre-defined RazorPages you can add, I can say they are mostly related to Identity actions like login, register, change password, ... you can have them with minimum amount of effort on your application.
for my case if I am not going to implement a complex identity model or if I don't want to have something other than asp.net identity for my application membership the Razor Pages are the fastest way of doing that , generally, RazorPages are compared with Mvc ViewComponents (personally I don't like to use it frequently and application-wide) (i think razor pages are using MVVM pattern)
long story short, I believe that the razor pages are the fastest and the more organized way of doing some small features in a project or even doing small projects but imagine you have too many actions in a big project, then you will have tons of razor pages which will be so hard to maintain.
I can recommend that go for mvc approach and use razor pages as needed, for both cases you can still inject your class/interface either to controller constructors or Razor page constructors and still using built-in asp.net core DI (services.AddScoped, services.AddTransient, services.AddSingleton)
here is the source code for Razor pages, you can look into it if you are in the mood ;) https://github.com/aspnet/Mvc/tree/master/src/Microsoft.AspNetCore.Mvc.RazorPages
Upvotes: 4