Hello, I am working with a Blazor project and I'm trying to work out how to create custom methods that would show up in the Load | Invoke DataSource Method.
So far I have attempted to create a service class that sits with the SecurityService and my datasource service, and add a scoped service via the Startup | ConfigureServices method, but this gets wiped out once back in Radzen and code regeneration is run.
Looking at the Startup Class I can see a Partial Method called OnConfigureServices and I'm wondering if I should create a Startup.Custom.cs file and add my service here.
Yes, you should create a Startup.Custom.cs partial class with the same namespace as the generated one and define a OnConfigureServices method where you register what you need.
Indeed the Invoke Data Source method dropdown lists only the data source methods. Custom services aren't listed there.
We are currently working on a new feature which is similar to the Invoke custom method available in Angular Radzen applications.
To invoke your service now you need to inject it first in the Page.cshtml.cs file (Radzen does not overwrite it) and then invoke via Execute C# action. Since the Page.cshtml.cs file is C# you have to use attribute injection:
public partial class PageComponent
{
// Dependency injection works even if using the
// InjectAttribute in a component's base class.
[Inject]
protected IDataAccess DataRepository { get; set; }
}
It turned out to do this:
partial void OnConfigureServices(IServiceCollection services)
{
(new IdentityBuilder(typeof(ApplicationUser), services)).AddErrorDescriber();
}
Sorry, need help again.
At the "Finishing touches" of create a complete application tutorial says:
The final step is to update the personal data when the user submits the form.
Add a new file server\Services\SecurityService.Custom.cs .
Add add a new partial method OnUserUpdated which will set the custom properties FirstName , LastName and Picture .
using System;
using System.Collections.Generic;
using RadzenCrm.Models;
namespace RadzenCrm
{
public partial class SecurityService
{
partial void OnUserUpdated(ApplicationUser user, ApplicationUser data)
{
user.FirstName = data.FirstName;
user.LastName = data.LastName;
user.Picture = data.Picture;
}
}
}
But generated SecurityService class isn't partial, so we can't declare another partial class...
Any ideas?
Hello Radzen Dev Team!
How to add custom datasource method to list?
I'm added DataService.custom.cs file with my method:
public partial class DataService
{
public void TestMethod()
{
}
}
But it won't appear in Invoke datasource method's list
I'm having issues with Custom DB methods in my partial class.
Sometimes the methods appear straight away when Invoking a Data Source Method, sometimes I have to restart Radzen several times before the method appears and sometimes I can't get the method to appear at all... hence why I am now asking for help.
Invoke Data Source Method will list only data source methods part of the data source meta. Invoke Method action will list custom methods that are defined in the page partial class.
Ok, but this is a DBService method. Surely you should be able to add DB methods to the DBService partial class and have them appear under the Invoke Data Source Method list.
It seems a bit of a workaround to use a page custom method to then call a DB custom method.
Is this something you could add in a future release?
As @enchev explained the Invoke Data Source method only lists the methods generated for a database or REST data source. Custom methods are not listed. We don't currently have plans to list them. The custom methods documentation is available here.