Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Akka.DependencyInjection: ServiceProviderProps is broken - needs to be rewritten #4853

Closed
Aaronontheweb opened this issue Mar 16, 2021 · 1 comment · Fixed by #4858
Closed

Comments

@Aaronontheweb
Copy link
Member

Version: 1.4.17

Ran into this while investigating petabridge/phobos-issues#16 - the problem is that any of the methods you might typically use on Props, i.e. Props.WithSupervisorStrategy et al don't work with the ServiceProviderProps.

Instead, we need to refactor that mechanism to use the IIndirectActorProducer much like how we did with the original Akka.DI.Core implementation here:

public class DIActorProducer : IIndirectActorProducer
{
private IDependencyResolver dependencyResolver;
private Type actorType;
readonly Func<ActorBase> actorFactory;
/// <summary>
/// Initializes a new instance of the <see cref="DIActorProducer"/> class.
/// </summary>
/// <param name="dependencyResolver">The resolver used to resolve the given actor type.</param>
/// <param name="actorType">The type of actor that this producer creates.</param>
/// <exception cref="ArgumentNullException">
/// This exception is thrown when either the specified <paramref name="dependencyResolver"/> or the specified <paramref name="actorType"/> is undefined.
/// </exception>
public DIActorProducer(IDependencyResolver dependencyResolver, Type actorType)
{
if (dependencyResolver == null) throw new ArgumentNullException(nameof(dependencyResolver), $"DIActorProducer requires {nameof(dependencyResolver)} to be provided");
if (actorType == null) throw new ArgumentNullException(nameof(actorType), $"DIActorProducer requires {nameof(actorType)} to be provided");
this.dependencyResolver = dependencyResolver;
this.actorType = actorType;
this.actorFactory = dependencyResolver.CreateActorFactory(actorType);
}
/// <summary>
/// Retrieves the type of the actor to produce.
/// </summary>
public Type ActorType
{
get { return this.actorType; }
}
/// <summary>
/// Creates an actor based on the container's implementation specific actor factory.
/// </summary>
/// <returns>An actor created by the container.</returns>
public ActorBase Produce()
{
return actorFactory();
}
/// <summary>
/// Signals the container that it can release its reference to the actor.
/// </summary>
/// <param name="actor">The actor to remove from the container.</param>
public void Release(ActorBase actor)
{
dependencyResolver.Release(actor);
}
}

So this is going to be a breaking change to Akka.DependencyInjection, although one that shouldn't have much real-world impact as the underlying types are all abstracted away from the users of the library and the ServiceProvider interface shouldn't have any problems with it.

@Aaronontheweb
Copy link
Member Author

Going to address #3599 while I'm at it

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant