Service injection question

I have a question that is probably more a newbie with Blazor problem than Radzen.

I have created a new service with functions to log various transactions and send out emails.
I then extended Statup.cs by creating a Statup.custom.cs with a services.AddScoped(); in the OnConfigureService function.

In VS2019 I am able to successfully inject the code in a page razor.designer.cs and use it successfully.

** protected SystemLogger SLog { get; set; }**

My only issue so far is that anytime that I modify anything on that page in Radzen, I lose the Inject code from the razor.designer.cs.
It must be something simple, but after hours, I haven't found a solution.

Hi @mwechter,

Radzen generates the *.designer.cs files and will overwrite any changes unless the file is added to the code generation ignore list.

More info:


Code generation ignore list


I understood the regeneration of the *.designer.cs files by Radzen.

I am able to get things to work well in Visual Studio, and I go back and forth between Radzen and VS all during the development process. Using Radzen's extensibility I have been able to get around all of my issues (so far) except this injection. The particular service injection will be required in most of my pages in order to log errors and user interactions.

I know how to get around this by using less of Radzen as I 'finish a page' and I can add that page to the ignore list. I was asking if there was a way, short of adding the page(s) to the ignore list, to add a service injection permanently into a designer page or perhaps a way to make my service injection act like one of the many injections automatically generated by Radzen for each page. (some type of dependency?)
I can live with an answer of no or maybe in the future.

Thanks for your assistance

Maybe you can add your code in a partial class then you don't need to add it to an ignore list.
and if the naming is correct it will be always in the same structure in VS.

public partial class NamePageComponent

and file structure:

  • NamePage.razor
  • NamePage.razor.cs
  • NamePage.razor.designer.cs
  • NamePage.razor.YourName.cs

You don't need to add it to the *.designer page. You can add it to the other one which Radzen generates only once. Here is a quote from the Architecture documentation link above:

2. <page-name>.razor.cs - C# partial class that is empty by default. This file is generated only once. Used for custom code.
3. <page-name>.razor.designer.cs - C# class that implements the Blazor component - handles UI component events (e.g. button clicks), loads data,

So by adding that property to the .razor.cs file it will be accessible everywhere in the page as it is a partial class.


I had earlier tried to add the injection to the razor.cs but my syntax would not compile.
A little more research and I found that in the razor.cs I needed to change the syntax to:

[Microsoft.AspNetCore.Components.Inject] protected SystemLogger SLog { get; set; }

Just needed to adorn the inject with Microsoft.AspNetCore.Components.
Everything is good now.

Thank you

@mwechter alternatively you could import the namespace

using Microsoft.AspNetCore.Components;