Radzen choose dependency injection methods

hello radzen team,
i have a question about a feature...
I have some code for exception handling (creating nice text for the user for DB Exceptions).
I inject the ExceptionService in the custom partial component.

[Inject]
public ExceptionService ExceptionService { get; set; }

now i must write a method

protected void Exception(Exception e)
{
    ExceptionService.FormatException(e,NotificationService);
}

in every component for the reason to use it in the designer


because i cannot choose the ExceptionService.FormatException() method from the Service directly
image

so i want to ask you if its possible to add a feature to the designer to choose also methods from DI objects not only methods in the partial component class?
something like chodsing a parameter property...

Video

Dont know if its hard to integrate in the radzen designer but worth the question :slight_smile:

kind regards
Thomas

You can use the page partial class to add your code.

@enchev,
yes. this is what i do now:

using Microsoft.AspNetCore.Components;
using Radzen;
using System;
using Trent.Services;

namespace Trent.Pages
{
    public partial class AddArtikelgruppeComponent
    {

        [Inject]
        public ParameterService ParameterService { get; set; }

        [Inject]
        public BrowserService BrowserService { get; set; }

        [Inject]
        public ExceptionService ExceptionService { get; set; }

        protected void Initialize()
        {

        }

        protected void Exception(Exception e)
        {
            ExceptionService.FormatException(e,NotificationService);
        }

        protected async void OnClose(int? addedEntityId)
        {
            if (ParameterService.OpenedAsDialog)
            {
                DialogService.Close(addedEntityId);
            }
            else
            {
                UriHelper.NavigateTo("artikelgruppe");
            }
        }
    }
}

I mean it were easier to define the ExceptionService.FormatException() method directly in the designer.
For now this isnt possible because the methods of injected objects are not shown in the "invoke method " list.

Thomas

I think that gives a great and easy to handle possibility to expand the customized code.

Only inject a service in the page partial class and then define the calling of the injected service methods directly in the designer.

Without to wrote more code in the page partial class. Only a Dependency Injection... Ready to use all the Methods in the Injected Class.

Thomas

1 Like