/// <summary> /// Retrieves the extension specified by a given type, <typeparamref name="T"/>, from a given actor system. /// If the extension does not exist within the actor system, then the extension specified by <paramref name="extensionId"/> /// is registered to the actor system. /// </summary> /// <typeparam name="T">The type associated with the extension to retrieve.</typeparam> /// <param name="system">The actor system from which to retrieve the extension or to register with if it does not exist.</param> /// <param name="extensionId">The type of the extension to register if it does not exist in the given actor system.</param> /// <returns>The extension retrieved from the given actor system.</returns> public static T WithExtension <T>(this ActorSystem system, Type extensionId) where T : class, IExtension { if (system.HasExtension <T>()) { return(system.GetExtension <T>()); } else { return((T)system.RegisterExtension((IExtensionId)Activator.CreateInstance(extensionId))); } }
/// <summary> /// Retrieves the extension specified by a given type, <typeparamref name="T"/>, from a given actor system. /// If the extension does not exist within the actor system, then the extension specified by <typeparamref name="TI"/> /// is registered to the actor system. /// </summary> /// <typeparam name="T">The type associated with the extension to retrieve.</typeparam> /// <typeparam name="TI">The type associated with the extension to retrieve if it does not exist within the system.</typeparam> /// <param name="system">The actor system from which to retrieve the extension or to register with if it does not exist.</param> /// <returns>The extension retrieved from the given actor system.</returns> public static T WithExtension <T, TI>(this ActorSystem system) where T : class, IExtension where TI : IExtensionId { if (system.HasExtension <T>()) { return(system.GetExtension <T>()); } else { return((T)system.RegisterExtension((IExtensionId)Activator.CreateInstance(typeof(TI)))); } }