Hello,
If you are like me, you might be using Coded Workflows because you value the automation power the platform brings, but you prefer to organize your projects in a way that is more similar to traditional application software.
UiPath allows you to register reuseable custom services via dependency injection, which is detailed in this documentation:
Studio - Registering custom services
However, there is one problem, by default, Code Source files have no means of logging to Orchestrator. This is unlike Coded Workflows which inherit the ability to this from their base class. So here is a quick guide on how to log in your custom services. If you are familiar with .NET Core application development, you will find it is very similar to how it is done there.
- Add logger service as an argument in the constructor of your custom service within the code source file. I also added ISystemService so I can get assets from Orchestrator easily in the constructor.
public HttpClientService(IOutputLoggerService loggerService, ISystemService sysService)
{
logger = loggerService;
system = sysService;
}
- Register in your Coded Workflow Partial Class
public partial class CodedWorkflow : CodedWorkflowBase
{
public IHttpClientService httpClientService { get => serviceContainer.Resolve<IHttpClientService>(); }
protected override void RegisterServices(ICodedWorkflowsServiceLocator serviceLocator)
{
serviceLocator.RegisterType<IHttpClientService, HttpClientService>(CodeServiceRegistrationType.Singleton);
}
}
And just like that you can now log in your custom service. Hope someone finds this helpful.