Category: .NET Core
-
NetCoreUsefullEndpoints–1- Idea
For every web Api that I produce I want to see if it is well configured . That means The error flows how it should,where it should ? ( API for error ) The user is authorized and authenticated ? What is the current environment that I have ? ( name of the host )…
-
DIForFunctions – Improving constructor–part 5
I have received a suggestion : what if we just put into constructor what we need,and everything else ( such as ILogger ) are into fields ? The Roslyn Source Code Generator will generate a constructor that calls the this constructor and will assign fields needed. Let’s give an example : We wrote public partial…
-
DIForFunctions–what it does- part 4
You can find a demo at https://github.com/ignatandrei/FunctionsDI/tree/main/src/FunctionsWithDI – see TestCOnsoleAPP. But let’s write here also Generate (constructor) and functions calls similar with ASP.NET Core WebAPI ( [FromServices] will be provided by DI ) Also,verifies for null . Usage Reference into the csproj <ItemGroup> <PackageReference Include=”RSCG_FunctionsWithDI” Version=”2022.6.19.1605″ ReferenceOutputAssembly=”false” OutputItemType=”Analyzer” /> <PackageReference Include=”RSCG_FunctionsWithDI_Base” Version=”2022.6.19.1605″ /> </ItemGroup> Then…
-
DIForFunctions–NuGet- part3
The important part now is to make public – that means NuGet and documentation,The NuGet is pretty simple – with dotnet pack and with GitHub Actions – in order to do automatically every time I modify the main. For now,this is the action name: .NET on: push: branches: [ “main” ] pull_request:…
-
DI for Functions- work–part 2
Let’s begin with tests – we need to have a class with multiple functions that have multiple [FromServices} parameter. Like public bool TestMyFunc1([FromServices] TestDI1 t1,[FromServices] TestDI2 t2,int x,int y) { return true; } public bool TestMyFunc2([FromServices] TestDI1 t12, int x,int y) { return true; } // more others Because there are multiple functions,I need to…
-
DI for Functions–idea – part 1
Looking at ASP.NET Core,there is a wonderful feature that gives you thinking : you can put in any action for a controller FromServices argument and the framework will complete from,well,services: : public ActionResult Test([FromServices] MyFunction What if you can do the same with any function from any class ? It will be good,but … how …
-
app.Use vs Middleware–and scoped services
When you want to use a fast middleware,you can use ( pun intended) app.Use( However,if you want to use some of scoped services,e.g. app.Use(async (context,next) => { var st= app.Services.GetRequiredService<IServerTiming>(); //code } then it gives an error Cannot resolve scoped service from root provider For this you should create a scope: app.Use(async (context,next) => { …
-
Services.Add => 2 NuGet
If you make a NuGet package for ASP.NET Core and you make an extension method that calls Services.AddWhatever in order to add a Sngleton / Scoped / Transient a IWhatever => Whatever implementation,please add IWhatever in a separate Nuget . Why ? Because not all ASP>NET Core projects are made of a single project –…
-
Passing from .NET 5 to .NET 6
First,read the document here: Migrate from ASP.NET Core 5.0 to 6.0 | Microsoft Docs .\ So those were my steps ( fully compile after each step ): 1. Replace in csproj net5.0 with net6.0 <TargetFramework>net6.0</TargetFramework> 2. Update all nugets reference to the latest version 3. Add globals.cs with various usings 4. Add globals.cs . Mine…
-
Templating Roslyn Source Code Generators
I want that,when I generate code with Roslyn,to have a template that I can easy modify to generate code . Also,I want to let the user ( the programmer,in this case) modify this template – maybe he has better ideas than me. For reading from the RSCG,is pretty simple: Make as an embedded resource and…