Closed pvivera closed 6 years ago
Thanks for the PR @pvivera.
I'm wondering if instead of using the Activator.CreateInstance
call the ActorService
type can instead be resolved from the container. That would allow other services to also be injected into it along with the standard set of parameters.
Do you think this additional capability would be useful to you when creating a custom ActorService
class? cc: @jefersonmanjos
@alexmg That was my thought at the first time but then looking the code I saw that is was using new ActorService to create the instance, so I took the decision to use CreateInstance. I've updated the PR to use a registered ActorService that it could be overridden by a custom one.
@alexmg this should be useful, but it's necessary allow generic type for actorservice. Because in the same application I need differents actorservices.
This the code that I use today to solve this problems. For each different actorservice I need to create a new function to register. So if we can create a generic way to register actor with actorservices, would be amazing.
`
public ServiceFabricStartupConfiguration RegisterActorCustomService
return new CustomActorService(
context,
actorTypeInfo,
(actorService, actorId) =>
{
var lifetimeScope = container.BeginLifetimeScope(builderLocal =>
{
builderLocal.RegisterInstance(context)
.As<StatefulServiceContext>()
.As<ServiceContext>();
builderLocal.RegisterInstance(actorService)
.As<ActorService>();
builderLocal.RegisterInstance(actorId)
.As<ActorId>();
});
var actorResolve = lifetimeScope.Resolve<T>();
return actorResolve;
});
});
}));
return this;
}`
I haven't forgotten this @pvivera. Hoping to hit this one tomorrow.
This change is in Autofac.ServiceFabric 2.1.0-develop-00053
on our MyGet feed (https://www.myget.org/F/autofac/api/v3/index.json
). It would be awesome if you could give it a test.
close #36