CustomerOrder.Actor.CustomerOrderActor.InternalActivateAsync C# (CSharp) Method

InternalActivateAsync() public method

Adding this method to support DI/Testing We need to do some work to create the actor object and make sure it is constructed completely In local testing we can inject the components we need, but in a real cluster those items are not established until the actor object is activated. Thus we need to have this method so that the tests can have the same init path as the actor would in prod
public InternalActivateAsync ( ICodePackageActivationContext context, IServiceProxyFactory proxyFactory ) : Task
context ICodePackageActivationContext
proxyFactory IServiceProxyFactory
return Task
        public async Task InternalActivateAsync(ICodePackageActivationContext context, IServiceProxyFactory proxyFactory)
        {
            this.tokenSource = new CancellationTokenSource();
            this.builder = new ServiceUriBuilder(context, InventoryServiceName);
            this.ServiceProxyFactory = proxyFactory;
        }

Usage Example

        private static async Task<CustomerOrderActor> CreateCustomerOrderActor(MockServiceProxyFactory serviceProxyFactory)
        {
            try
            {
                CustomerOrderActor target = new CustomerOrderActor(
                    new ActorService(
                        context: statefulServiceContext,
                        actorTypeInfo: ActorTypeInformation.Get(typeof(CustomerOrderActor)),
                        stateManagerFactory: (actorBase, stateProvider) => new MockActorStateManager()),
                    new ActorId(Guid.NewGuid()));

                await target.InternalActivateAsync(codePackageContext, serviceProxyFactory);

                return target;
            }
            catch (Exception e)
            {
                throw;
            }
        }