Category: .NET Core
-
NetCoreUsefullEndpoints-4 Nuget package
or NugetPackages there is a simple .NET Pack CLI command and many configurations However,it is not so simple . See https://docs.microsoft.com/en-us/nuget/create-packages/package-authoring-best-practices . In practice,I have a readme.md file ( for showing on nuget.org ) and a readme.txt file( for the programmer to show help after installing the package) THis is what I have in the…
-
NetCoreUsefullEndpoints-2–MVP
So let’s start the implementation for user / error / environment. The only difficulty resides in the fact that IEndpointRouteBuilder is not defined into a usual library,but the dll csproj must contain <ItemGroup> <FrameworkReference Include=”Microsoft.AspNetCore.App” /> </ItemGroup> Otherwise,it is work as usual. For example,for seeing a user public static void MapUser(this IEndpointRouteBuilder route) { ArgumentNullException.ThrowIfNull(route);…
-
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 –…