-
Notifications
You must be signed in to change notification settings - Fork 1k
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
ServiceProviderProps and Props Changes #4858
Changes from all commits
c6c6bd3
ca66c8c
8d2f0f4
0e354de
ae74ec5
8344974
f232509
7b6b2e4
b829a8c
bcff026
485700a
5ac83ce
6c7808f
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -47,21 +47,6 @@ public static ServiceProvider For(ActorSystem actorSystem) | |
return actorSystem.WithExtension<ServiceProvider, ServiceProviderExtension>(); | ||
} | ||
|
||
///// <summary> | ||
///// Uses a delegate to dynamically instantiate an actor where some of the constructor arguments are populated via dependency injection | ||
///// and others are not. | ||
///// </summary> | ||
///// <remarks> | ||
///// YOU ARE RESPONSIBLE FOR MANAGING THE LIFECYCLE OF YOUR OWN DEPENDENCIES. AKKA.NET WILL NOT ATTEMPT TO DO IT FOR YOU. | ||
///// </remarks> | ||
///// <typeparam name="T">The type of actor to instantiate.</typeparam> | ||
///// <param name="producer">The delegate used to create a new instance of your actor type.</param> | ||
///// <returns>A new <see cref="Props"/> instance which uses DI internally.</returns> | ||
//public Props Props<T>(Func<IServiceProvider, T> producer) where T : ActorBase | ||
//{ | ||
// return new ServiceProviderProps<T>(producer, Provider); | ||
//} | ||
|
||
/// <summary> | ||
/// Uses a delegate to dynamically instantiate an actor where some of the constructor arguments are populated via dependency injection | ||
/// and others are not. | ||
|
@@ -74,7 +59,7 @@ public static ServiceProvider For(ActorSystem actorSystem) | |
/// <returns>A new <see cref="Akka.Actor.Props"/> instance which uses DI internally.</returns> | ||
public Props Props<T>(params object[] args) where T : ActorBase | ||
{ | ||
return new ServiceProviderProps<T>(Provider, args); | ||
return Akka.Actor.Props.CreateBy(new ServiceProviderActorProducer<T>(Provider, args)); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Use the new |
||
} | ||
} | ||
|
||
|
@@ -99,51 +84,33 @@ public override ServiceProvider CreateExtension(ExtendedActorSystem system) | |
} | ||
|
||
/// <summary> | ||
/// This class represents a specialized <see cref="Akka.Actor.Props"/> that uses delegate invocation | ||
/// to create new actor instances, rather than a traditional <see cref="System.Activator"/>. | ||
/// INTERNAL API | ||
/// | ||
/// Relies on having an active <see cref="IServiceProvider"/> implementation available | ||
/// Used to create actors via the <see cref="ActivatorUtilities"/>. | ||
/// </summary> | ||
/// <typeparam name="TActor">The type of the actor to create.</typeparam> | ||
internal class ServiceProviderProps<TActor> : Props where TActor : ActorBase | ||
/// <typeparam name="TActor">the actor type</typeparam> | ||
internal sealed class ServiceProviderActorProducer<TActor> : IIndirectActorProducer where TActor:ActorBase | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Refactor the |
||
{ | ||
private readonly IServiceProvider _provider; | ||
private readonly object[] _args; | ||
|
||
/// <summary> | ||
/// Initializes a new instance of the <see cref="ServiceProviderProps{TActor}" /> class. | ||
/// </summary> | ||
/// <param name="provider">The <see cref="IServiceProvider"/> used to power this class</param> | ||
/// <param name="args">The constructor arguments passed to the actor's constructor.</param> | ||
public ServiceProviderProps(IServiceProvider provider, params object[] args) | ||
: base(typeof(TActor), args) | ||
public ServiceProviderActorProducer(IServiceProvider provider, object[] args) | ||
{ | ||
_provider = provider; | ||
_args = args; | ||
ActorType = typeof(TActor); | ||
} | ||
|
||
/// <summary> | ||
/// Creates a new actor using the configured factory method. | ||
/// </summary> | ||
/// <returns>The actor created using the factory method.</returns> | ||
public override ActorBase NewActor() | ||
public ActorBase Produce() | ||
{ | ||
return ActivatorUtilities.CreateInstance<TActor>(_provider, Arguments); | ||
return (ActorBase)ActivatorUtilities.CreateInstance(_provider, ActorType, _args); | ||
} | ||
|
||
#region Copy methods | ||
public Type ActorType { get; } | ||
|
||
/// <summary> | ||
/// Creates a copy of the current instance. | ||
/// </summary> | ||
/// <returns>The newly created <see cref="Akka.Actor.Props"/></returns> | ||
protected override Props Copy() | ||
public void Release(ActorBase actor) | ||
{ | ||
return new ServiceProviderProps<TActor>(_provider, Arguments) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. no-op for this class - scopes are meant to be managed directly by the users. |
||
{ | ||
Deploy = Deploy, | ||
SupervisorStrategy = SupervisorStrategy | ||
}; | ||
// no-op | ||
} | ||
|
||
#endregion | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -1408,8 +1408,11 @@ namespace Akka.Actor | |
public static Akka.Actor.Props Create<TActor>(Akka.Actor.SupervisorStrategy supervisorStrategy) | ||
where TActor : Akka.Actor.ActorBase, new () { } | ||
public static Akka.Actor.Props Create(System.Type type, params object[] args) { } | ||
[System.ObsoleteAttribute("Do not use this method. Call CreateBy(IIndirectActorProducer, params object[] arg" + | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. All public API changes made to the |
||
"s) instead")] | ||
public static Akka.Actor.Props CreateBy<TProducer>(params object[] args) | ||
where TProducer : class, Akka.Actor.IIndirectActorProducer { } | ||
public static Akka.Actor.Props CreateBy(Akka.Actor.IIndirectActorProducer producer, params object[] args) { } | ||
public bool Equals(Akka.Actor.Props other) { } | ||
public override bool Equals(object obj) { } | ||
public override int GetHashCode() { } | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Commented out method - just removed it.