How to register an instance for dependency injection?

Hi all,

I am trying to register a service for dependency injection in my coded automation using the instructions described here:

Studio - Registering custom services (uipath.com)

Does anyone know why this code is not returning the same myService instance every time I use myService between different Coded Workflows?

using UiPath.CodedWorkflows;

namespace CodedSandbox
{
    public partial class CodedWorkflow : CodedWorkflowBase
    {
        public IMyService myService { get => serviceContainer.Resolve<IMyService>(); }

        protected override void RegisterServices(ICodedWorkflowsServiceLocator serviceLocator)
        {      
            base.RegisterServices(serviceLocator);
            var _myService  = new MyService();
            serviceLocator.RegisterInstance<IMyService>(_myService );
        }
    }
}

If I set a property of myService to something in a Coded Workflow, then access myService and access the property, its null.

E.g.

CodedWorkflow1:

myService.ID = 1;

CodedWorkflow2:

var ID = myService.ID; // Returns null

Thanks,

Tim

Hello, can you provide the code for the service?