Category: di

  • DIForFunctions–improving generating of a constructor for a existing class with Roslyn

    It is not so difficult to generate a new constructor for a existing class with Roslyn – however,there are some difficulties: 1. The original class must be declared “partial” – you cannot declare the second as partial if the first was not 2.  The new class must be in the same namespace ( or without…

  • 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–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 …

  • Dependency injection choice

    For a personal pet project I have needed a DI framework . It relates to WebApi – I need to switch the provider for web api between a console and web – mostly authentication / logging different. Some years ago was only StructureMap – but now there are a lot. So I started to investigate…