From 6e5dc1eb5bcc88e2b89588a89da4e9347f9d7069 Mon Sep 17 00:00:00 2001 From: Gregorius Soedharmo Date: Thu, 16 Jun 2022 03:54:02 +0700 Subject: [PATCH] Remove old Akka.DI dependency injection projects (#6003) --- src/Akka.sln | 30 -- .../Akka.DI.Core/Akka.DI.Core.csproj | 24 - .../Akka.DI.Core/DIActorContextAdapter.cs | 72 --- .../Akka.DI.Core/DIActorProducer.cs | 67 --- .../Akka.DI.Core/DIActorSystemAdapter.cs | 60 --- .../dependencyinjection/Akka.DI.Core/DIExt.cs | 44 -- .../Akka.DI.Core/DIExtension.cs | 33 -- .../Akka.DI.Core/Extensions.cs | 81 ---- .../Akka.DI.Core/IDependencyResolver.cs | 49 --- .../Akka.DI.Core/Properties/AssemblyInfo.cs | 22 - .../Akka.DI.Core/Readme.md | 182 -------- .../Akka.DI.TestKit/Akka.DI.TestKit.csproj | 30 -- .../Akka.DI.TestKit/DiResolverSpec.cs | 411 ------------------ .../Properties/AssemblyInfo.cs | 22 - 14 files changed, 1127 deletions(-) delete mode 100644 src/contrib/dependencyinjection/Akka.DI.Core/Akka.DI.Core.csproj delete mode 100644 src/contrib/dependencyinjection/Akka.DI.Core/DIActorContextAdapter.cs delete mode 100644 src/contrib/dependencyinjection/Akka.DI.Core/DIActorProducer.cs delete mode 100644 src/contrib/dependencyinjection/Akka.DI.Core/DIActorSystemAdapter.cs delete mode 100644 src/contrib/dependencyinjection/Akka.DI.Core/DIExt.cs delete mode 100644 src/contrib/dependencyinjection/Akka.DI.Core/DIExtension.cs delete mode 100644 src/contrib/dependencyinjection/Akka.DI.Core/Extensions.cs delete mode 100644 src/contrib/dependencyinjection/Akka.DI.Core/IDependencyResolver.cs delete mode 100644 src/contrib/dependencyinjection/Akka.DI.Core/Properties/AssemblyInfo.cs delete mode 100644 src/contrib/dependencyinjection/Akka.DI.Core/Readme.md delete mode 100644 src/contrib/dependencyinjection/Akka.DI.TestKit/Akka.DI.TestKit.csproj delete mode 100644 src/contrib/dependencyinjection/Akka.DI.TestKit/DiResolverSpec.cs delete mode 100644 src/contrib/dependencyinjection/Akka.DI.TestKit/Properties/AssemblyInfo.cs diff --git a/src/Akka.sln b/src/Akka.sln index a06864509d8..67435b855db 100644 --- a/src/Akka.sln +++ b/src/Akka.sln @@ -154,10 +154,6 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Transports", "Transports", EndProject Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "DependencyInjection", "DependencyInjection", "{48845655-5E60-40AB-A798-F118CC1CF510}" EndProject -Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Akka.DI.Core", "contrib\dependencyinjection\Akka.DI.Core\Akka.DI.Core.csproj", "{3DCFADA2-02DF-41AD-A907-F805B86A5DFE}" -EndProject -Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Akka.DI.TestKit", "contrib\dependencyinjection\Akka.DI.TestKit\Akka.DI.TestKit.csproj", "{539317E7-EEEF-4BE5-A12D-6BB048E7A1E3}" -EndProject Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Akka.TestKit.Xunit", "contrib\testkits\Akka.TestKit.Xunit\Akka.TestKit.Xunit.csproj", "{E7A836C1-42D3-4ADC-81C6-C6C5398CC740}" EndProject Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Akka.Cluster.Tests.Performance", "core\Akka.Cluster.Tests.Performance\Akka.Cluster.Tests.Performance.csproj", "{94C10096-C33E-404E-B0FB-F8535512A952}" @@ -717,30 +713,6 @@ Global {E3549E17-7206-44F0-A322-EDC058A0498F}.Release|Any CPU.Build.0 = Release|Any CPU {E3549E17-7206-44F0-A322-EDC058A0498F}.Release|x64.ActiveCfg = Release|Any CPU {E3549E17-7206-44F0-A322-EDC058A0498F}.Release|x86.ActiveCfg = Release|Any CPU - {3DCFADA2-02DF-41AD-A907-F805B86A5DFE}.Debug|Any CPU.ActiveCfg = Debug|Any CPU - {3DCFADA2-02DF-41AD-A907-F805B86A5DFE}.Debug|Any CPU.Build.0 = Debug|Any CPU - {3DCFADA2-02DF-41AD-A907-F805B86A5DFE}.Debug|x64.ActiveCfg = Debug|Any CPU - {3DCFADA2-02DF-41AD-A907-F805B86A5DFE}.Debug|x64.Build.0 = Debug|Any CPU - {3DCFADA2-02DF-41AD-A907-F805B86A5DFE}.Debug|x86.ActiveCfg = Debug|Any CPU - {3DCFADA2-02DF-41AD-A907-F805B86A5DFE}.Debug|x86.Build.0 = Debug|Any CPU - {3DCFADA2-02DF-41AD-A907-F805B86A5DFE}.Release|Any CPU.ActiveCfg = Release|Any CPU - {3DCFADA2-02DF-41AD-A907-F805B86A5DFE}.Release|Any CPU.Build.0 = Release|Any CPU - {3DCFADA2-02DF-41AD-A907-F805B86A5DFE}.Release|x64.ActiveCfg = Release|Any CPU - {3DCFADA2-02DF-41AD-A907-F805B86A5DFE}.Release|x64.Build.0 = Release|Any CPU - {3DCFADA2-02DF-41AD-A907-F805B86A5DFE}.Release|x86.ActiveCfg = Release|Any CPU - {3DCFADA2-02DF-41AD-A907-F805B86A5DFE}.Release|x86.Build.0 = Release|Any CPU - {539317E7-EEEF-4BE5-A12D-6BB048E7A1E3}.Debug|Any CPU.ActiveCfg = Debug|Any CPU - {539317E7-EEEF-4BE5-A12D-6BB048E7A1E3}.Debug|Any CPU.Build.0 = Debug|Any CPU - {539317E7-EEEF-4BE5-A12D-6BB048E7A1E3}.Debug|x64.ActiveCfg = Debug|Any CPU - {539317E7-EEEF-4BE5-A12D-6BB048E7A1E3}.Debug|x64.Build.0 = Debug|Any CPU - {539317E7-EEEF-4BE5-A12D-6BB048E7A1E3}.Debug|x86.ActiveCfg = Debug|Any CPU - {539317E7-EEEF-4BE5-A12D-6BB048E7A1E3}.Debug|x86.Build.0 = Debug|Any CPU - {539317E7-EEEF-4BE5-A12D-6BB048E7A1E3}.Release|Any CPU.ActiveCfg = Release|Any CPU - {539317E7-EEEF-4BE5-A12D-6BB048E7A1E3}.Release|Any CPU.Build.0 = Release|Any CPU - {539317E7-EEEF-4BE5-A12D-6BB048E7A1E3}.Release|x64.ActiveCfg = Release|Any CPU - {539317E7-EEEF-4BE5-A12D-6BB048E7A1E3}.Release|x64.Build.0 = Release|Any CPU - {539317E7-EEEF-4BE5-A12D-6BB048E7A1E3}.Release|x86.ActiveCfg = Release|Any CPU - {539317E7-EEEF-4BE5-A12D-6BB048E7A1E3}.Release|x86.Build.0 = Release|Any CPU {E7A836C1-42D3-4ADC-81C6-C6C5398CC740}.Debug|Any CPU.ActiveCfg = Debug|Any CPU {E7A836C1-42D3-4ADC-81C6-C6C5398CC740}.Debug|Any CPU.Build.0 = Debug|Any CPU {E7A836C1-42D3-4ADC-81C6-C6C5398CC740}.Debug|x64.ActiveCfg = Debug|Any CPU @@ -1393,8 +1365,6 @@ Global {E3549E17-7206-44F0-A322-EDC058A0498F} = {0E55F1F8-E212-43D7-A0C0-ACEA9794B0D7} {6AD34FA4-7584-454D-ACD4-A8911E0BDB00} = {588C1513-FAB6-42C3-B6FC-3485F13620CF} {48845655-5E60-40AB-A798-F118CC1CF510} = {588C1513-FAB6-42C3-B6FC-3485F13620CF} - {3DCFADA2-02DF-41AD-A907-F805B86A5DFE} = {48845655-5E60-40AB-A798-F118CC1CF510} - {539317E7-EEEF-4BE5-A12D-6BB048E7A1E3} = {48845655-5E60-40AB-A798-F118CC1CF510} {E7A836C1-42D3-4ADC-81C6-C6C5398CC740} = {7625FD95-4B2C-4A5B-BDD5-94B1493FAC8E} {94C10096-C33E-404E-B0FB-F8535512A952} = {01167D3C-49C4-4CDE-9787-C176D139ACDD} {99CCB7CA-E1EE-4497-BF52-2200A0EC5CB1} = {76F58DC4-19F1-43EF-A6E2-EC1CC8395AC5} diff --git a/src/contrib/dependencyinjection/Akka.DI.Core/Akka.DI.Core.csproj b/src/contrib/dependencyinjection/Akka.DI.Core/Akka.DI.Core.csproj deleted file mode 100644 index c4c0ea24639..00000000000 --- a/src/contrib/dependencyinjection/Akka.DI.Core/Akka.DI.Core.csproj +++ /dev/null @@ -1,24 +0,0 @@ - - - - - Akka.DI.Core - Dependency injection support for Akka.NET [DEPRECATED - replaced by Akka.DependencyInjection] - $(NetStandardLibVersion) - $(AkkaPackageTags);dependency injection - true - - - - - - - - $(DefineConstants);RELEASE - - - - - - - diff --git a/src/contrib/dependencyinjection/Akka.DI.Core/DIActorContextAdapter.cs b/src/contrib/dependencyinjection/Akka.DI.Core/DIActorContextAdapter.cs deleted file mode 100644 index 769d011f2ab..00000000000 --- a/src/contrib/dependencyinjection/Akka.DI.Core/DIActorContextAdapter.cs +++ /dev/null @@ -1,72 +0,0 @@ -//----------------------------------------------------------------------- -// -// Copyright (C) 2009-2021 Lightbend Inc. -// Copyright (C) 2013-2021 .NET Foundation -// -//----------------------------------------------------------------------- - -using System; -using Akka.Actor; - -namespace Akka.DI.Core -{ - /// - /// This class represents an adapter used to generate configuration - /// objects using the dependency injection (DI) extension using a given actor context. - /// - public class DIActorContextAdapter - { - readonly DIExt producer; - readonly IActorContext context; - - /// - /// Initializes a new instance of the class. - /// - /// The actor context associated with a system that contains the DI extension. - /// - /// This exception is thrown when the specified is undefined. - /// - /// - /// This exception is thrown when the Dependency Resolver has not been configured in the . - /// - public DIActorContextAdapter(IActorContext context) - { - if (context == null) throw new ArgumentNullException(nameof(context), $"DIActorContextAdapter requires {nameof(context)} to be provided"); - this.context = context; - this.producer = context.System.GetExtension(); - if (producer == null) throw new InvalidOperationException("The Dependency Resolver has not been configured yet"); - } - - /// - /// Obsolete. Use or methods for actor creation. This method will be removed in future versions. - /// - /// N/A - /// N/A - /// N/A - [Obsolete("Use Props methods for actor creation. This method will be removed in future versions")] - public IActorRef ActorOf(string name = null) where TActor : ActorBase - { - return context.ActorOf(producer.Props(typeof(TActor)), name); - } - - /// - /// Creates a configuration object for a given actor type. - /// - /// The actor type for which to create the configuration. - /// A configuration object for the given actor type. - public Props Props(Type actorType) - { - return producer.Props(actorType); - } - - /// - /// Creates a configuration object for a given actor type. - /// - /// The actor type for which to create the configuration. - /// A configuration object for the given actor type. - public Props Props() where TActor : ActorBase - { - return Props(typeof(TActor)); - } - } -} diff --git a/src/contrib/dependencyinjection/Akka.DI.Core/DIActorProducer.cs b/src/contrib/dependencyinjection/Akka.DI.Core/DIActorProducer.cs deleted file mode 100644 index 08bdb1dc0c2..00000000000 --- a/src/contrib/dependencyinjection/Akka.DI.Core/DIActorProducer.cs +++ /dev/null @@ -1,67 +0,0 @@ -//----------------------------------------------------------------------- -// -// Copyright (C) 2009-2021 Lightbend Inc. -// Copyright (C) 2013-2021 .NET Foundation -// -//----------------------------------------------------------------------- - -using System; -using Akka.Actor; - -namespace Akka.DI.Core -{ - /// - /// This class represents an actor creation strategy that uses dependency injection (DI) to resolve and instantiate actors based on their type. - /// - public class DIActorProducer : IIndirectActorProducer - { - private IDependencyResolver dependencyResolver; - private Type actorType; - - readonly Func actorFactory; - - /// - /// Initializes a new instance of the class. - /// - /// The resolver used to resolve the given actor type. - /// The type of actor that this producer creates. - /// - /// This exception is thrown when either the specified or the specified is undefined. - /// - 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); - } - - /// - /// Retrieves the type of the actor to produce. - /// - public Type ActorType - { - get { return this.actorType; } - } - - /// - /// Creates an actor based on the container's implementation specific actor factory. - /// - /// An actor created by the container. - public ActorBase Produce() - { - return actorFactory(); - } - - /// - /// Signals the container that it can release its reference to the actor. - /// - /// The actor to remove from the container. - public void Release(ActorBase actor) - { - dependencyResolver.Release(actor); - } - } -} diff --git a/src/contrib/dependencyinjection/Akka.DI.Core/DIActorSystemAdapter.cs b/src/contrib/dependencyinjection/Akka.DI.Core/DIActorSystemAdapter.cs deleted file mode 100644 index 0764a8b07d1..00000000000 --- a/src/contrib/dependencyinjection/Akka.DI.Core/DIActorSystemAdapter.cs +++ /dev/null @@ -1,60 +0,0 @@ -//----------------------------------------------------------------------- -// -// Copyright (C) 2009-2021 Lightbend Inc. -// Copyright (C) 2013-2021 .NET Foundation -// -//----------------------------------------------------------------------- - -using System; -using Akka.Actor; - -namespace Akka.DI.Core -{ - /// - /// This class represents an adapter used to generate configuration - /// objects using the dependency injection (DI) extension using a given actor system. - /// - public class DIActorSystemAdapter - { - readonly DIExt producer; - readonly ActorSystem system; - - /// - /// Initializes a new instance of the class. - /// - /// The actor system that contains the DI extension. - /// - /// This exception is thrown when the specified is undefined. - /// - /// - /// This exception is thrown when the Dependency Resolver has not been configured in the . - /// - public DIActorSystemAdapter(ActorSystem system) - { - if (system == null) throw new ArgumentNullException(nameof(system), $"DIActorSystemAdapter requires {nameof(system)} to be provided"); - this.system = system; - this.producer = system.GetExtension(); - if (producer == null) throw new InvalidOperationException("The Dependency Resolver has not been configured yet"); - } - - /// - /// Creates a configuration object for a given actor type. - /// - /// The actor type for which to create the configuration. - /// A configuration object for the given actor type. - public Props Props(Type actorType) - { - return producer.Props(actorType); - } - - /// - /// Creates a configuration object for a given actor type. - /// - /// The actor type for which to create the configuration. - /// A configuration object for the given actor type. - public Props Props() where TActor : ActorBase - { - return Props(typeof(TActor)); - } - } -} diff --git a/src/contrib/dependencyinjection/Akka.DI.Core/DIExt.cs b/src/contrib/dependencyinjection/Akka.DI.Core/DIExt.cs deleted file mode 100644 index 6a8b32a5827..00000000000 --- a/src/contrib/dependencyinjection/Akka.DI.Core/DIExt.cs +++ /dev/null @@ -1,44 +0,0 @@ -//----------------------------------------------------------------------- -// -// Copyright (C) 2009-2021 Lightbend Inc. -// Copyright (C) 2013-2021 .NET Foundation -// -//----------------------------------------------------------------------- - -using System; -using Akka.Actor; - -namespace Akka.DI.Core -{ - /// - /// This class represents an extension used to create - /// configuration objects using a dependency injection (DI) container. - /// - public class DIExt : IExtension - { - private IDependencyResolver dependencyResolver; - - /// - /// Initializes the extension to use a given DI resolver. - /// - /// The resolver used to resolve types from the DI container. - /// - /// This exception is thrown when the specified is undefined. - /// - public void Initialize(IDependencyResolver dependencyResolver) - { - if (dependencyResolver == null) throw new ArgumentNullException(nameof(dependencyResolver), $"DIExt requires {nameof(dependencyResolver)} to be provided"); - this.dependencyResolver = dependencyResolver; - } - - /// - /// Creates a configuration object for a given actor type. - /// - /// The actor type for which to create the configuration. - /// A configuration object for the given actor type. - public Props Props(Type actorType) - { - return new Props(typeof(DIActorProducer), new object[] { dependencyResolver, actorType }); - } - } -} diff --git a/src/contrib/dependencyinjection/Akka.DI.Core/DIExtension.cs b/src/contrib/dependencyinjection/Akka.DI.Core/DIExtension.cs deleted file mode 100644 index 5f89dde1ebc..00000000000 --- a/src/contrib/dependencyinjection/Akka.DI.Core/DIExtension.cs +++ /dev/null @@ -1,33 +0,0 @@ -//----------------------------------------------------------------------- -// -// Copyright (C) 2009-2021 Lightbend Inc. -// Copyright (C) 2013-2021 .NET Foundation -// -//----------------------------------------------------------------------- - -using Akka.Actor; - -namespace Akka.DI.Core -{ - /// - /// This class represents an provider used to create the dependency injection (DI) extension. - /// - public class DIExtension : ExtensionIdProvider - { - /// - /// A static reference to the current provider. - /// - public static DIExtension DIExtensionProvider = new DIExtension(); - - /// - /// Creates the dependency injection extension using a given actor system. - /// - /// The actor system to use when creating the extension. - /// The extension created using the given actor system. - public override DIExt CreateExtension(ExtendedActorSystem system) - { - var extension = new DIExt(); - return extension; - } - } -} diff --git a/src/contrib/dependencyinjection/Akka.DI.Core/Extensions.cs b/src/contrib/dependencyinjection/Akka.DI.Core/Extensions.cs deleted file mode 100644 index d8b3b732e30..00000000000 --- a/src/contrib/dependencyinjection/Akka.DI.Core/Extensions.cs +++ /dev/null @@ -1,81 +0,0 @@ -//----------------------------------------------------------------------- -// -// Copyright (C) 2009-2021 Lightbend Inc. -// Copyright (C) 2013-2021 .NET Foundation -// -//----------------------------------------------------------------------- - -using System; -using System.Collections.Generic; -using System.Linq; -using System.Reflection; -using Akka.Actor; - -namespace Akka.DI.Core -{ - /// - /// This class contains extension methods used to simplify working with dependency injection (DI) inside an . - /// - public static class Extensions - { - /// - /// Registers a dependency resolver with a given actor system. - /// - /// The actor system in which to register the given dependency resolver. - /// The dependency resolver being registered to the actor system. - /// - /// This exception is thrown when either the specified or the specified is undefined. - /// - public static void AddDependencyResolver(this ActorSystem system, IDependencyResolver dependencyResolver) - { - if (system == null) throw new ArgumentNullException(nameof(system), $"ActorSystem requires a valid {nameof(system)}"); - if (dependencyResolver == null) throw new ArgumentNullException(nameof(dependencyResolver), $"ActorSystem requires {nameof(dependencyResolver)} to be provided"); - system.RegisterExtension(DIExtension.DIExtensionProvider); - DIExtension.DIExtensionProvider.Get(system).Initialize(dependencyResolver); - } - - /// - /// Creates an adapter used to generate configuration objects using the DI extension using a given actor system. - /// - /// The actor system that contains the DI extension. - /// An adapter used to generate configuration objects using the DI extension. - public static DIActorSystemAdapter DI(this ActorSystem system) - { - return new DIActorSystemAdapter(system); - } - - /// - /// Creates an adapter used to generate configuration objects using the DI extension using a given actor context. - /// - /// The actor context associated with a system that contains the DI extension. - /// An adapter used to generate configuration objects using the DI extension. - public static DIActorContextAdapter DI(this IActorContext context) - { - return new DIActorContextAdapter(context); - } - - /// - /// Retrieves the with a given name from the current . - /// - /// The string representation of the type to retrieve. - /// The with the given name. - public static Type GetTypeValue(this string typeName) - { - var firstTry = Type.GetType(typeName); - Func searchForType = () => - GetLoadedAssemblies() - .SelectMany(x => x.GetTypes()) - .FirstOrDefault(t => t.Name.Equals(typeName)); - return firstTry ?? searchForType(); - } - - /// - /// Gets the list of loaded assemblies - /// - /// The list of loaded assemblies - private static IEnumerable GetLoadedAssemblies() - { - return AppDomain.CurrentDomain.GetAssemblies(); - } - } -} diff --git a/src/contrib/dependencyinjection/Akka.DI.Core/IDependencyResolver.cs b/src/contrib/dependencyinjection/Akka.DI.Core/IDependencyResolver.cs deleted file mode 100644 index 093372f5234..00000000000 --- a/src/contrib/dependencyinjection/Akka.DI.Core/IDependencyResolver.cs +++ /dev/null @@ -1,49 +0,0 @@ -//----------------------------------------------------------------------- -// -// Copyright (C) 2009-2021 Lightbend Inc. -// Copyright (C) 2013-2021 .NET Foundation -// -//----------------------------------------------------------------------- - -using System; -using Akka.Actor; - -namespace Akka.DI.Core -{ - /// - /// Defines services used by the extension system to create actors - /// - public interface IDependencyResolver - { - /// - /// Retrieves an actor's type with the specified name - /// - /// The name of the actor to retrieve - /// The type with the specified actor name - Type GetType(string actorName); - /// - /// Creates a delegate factory used to create actors based on their type - /// - /// The type of actor that the factory builds - /// A delegate factory used to create actors - Func CreateActorFactory(Type actorType); - /// - /// Used to register the configuration for an actor of the specified type - /// - /// The type of actor the configuration is based - /// The configuration object for the given actor type - Props Create() where TActor : ActorBase; - /// - /// Used to register the configuration for an actor of the specified type - /// - /// The of actor the configuration is based - /// The configuration object for the given actor type - Props Create(Type actorType); - /// - /// Signals the container to release it's reference to the actor. - /// - /// The actor to remove from the container - void Release(ActorBase actor); - } -} - diff --git a/src/contrib/dependencyinjection/Akka.DI.Core/Properties/AssemblyInfo.cs b/src/contrib/dependencyinjection/Akka.DI.Core/Properties/AssemblyInfo.cs deleted file mode 100644 index ed15ec84575..00000000000 --- a/src/contrib/dependencyinjection/Akka.DI.Core/Properties/AssemblyInfo.cs +++ /dev/null @@ -1,22 +0,0 @@ -//----------------------------------------------------------------------- -// -// Copyright (C) 2009-2021 Lightbend Inc. -// Copyright (C) 2013-2021 .NET Foundation -// -//----------------------------------------------------------------------- - -using System.Reflection; -using System.Runtime.InteropServices; - -// General Information about an assembly is controlled through the following -// set of attributes. Change these attribute values to modify the information -// associated with an assembly. - -// Setting ComVisible to false makes the types in this assembly not visible -// to COM components. If you need to access a type in this assembly from -// COM, set the ComVisible attribute to true on that type. -[assembly: ComVisible(false)] - -// The following GUID is for the ID of the typelib if this project is exposed to COM -[assembly: Guid("58efce02-ae94-4ce2-a9b0-1b2fda47f203")] - diff --git a/src/contrib/dependencyinjection/Akka.DI.Core/Readme.md b/src/contrib/dependencyinjection/Akka.DI.Core/Readme.md deleted file mode 100644 index 971b6738ed6..00000000000 --- a/src/contrib/dependencyinjection/Akka.DI.Core/Readme.md +++ /dev/null @@ -1,182 +0,0 @@ -#Akka.DI.Core - -**Actor Producer Extension** library used to create Dependency Injection Container for the [Akka.NET](https://github.com/akkadotnet/akka.net) framework. - -To learn more about using Dependency Injection in .NET, see [here]( http://www.amazon.com/Dependency-Injection-NET-Mark-Seemann/dp/1935182501/ref=sr_1_1?ie=UTF8&qid=1425861096&sr=8-1&keywords=mark+seemann). - -#What is it? - -**Akka.DI.Core** is an **ActorSystem extension** library for the Akka.NET framework that provides a simple way to create an Actor Dependency Resolver that can be used as an alternative to the basic capabilities of [Props](http://getakka.net/docs/Props) when you have actors with multiple dependencies. - -#How do you create an Extension? - -* Create a new class library -* Reference your favorite IoC Container, the Akka.DI.Core and of course Akka -* Create a class that implements ```IDependencyResolver``` - -Let's walk through the process of creating one for the CastleWindsor container. You need to create a new project named Akka.DI.CastleWindsor with all the necessary references including Akka.DI.Core, Akka and CastleWindsor. Name the initial class ```WindsorDependencyResolver```. - -```csharp -public class WindsorDependencyResolver : IDependencyResolver -{ - // we'll implement IDependencyResolver in the following steps -} -``` - -Add a constructor and private fields. - -```csharp -private IWindsorContainer _container; -private ConcurrentDictionary _typeCache; -private ActorSystem _system; - -public WindsorDependencyResolver(IWindsorContainer container, ActorSystem system) -{ - if (system == null) throw new ArgumentNullException("system"); - if (container == null) throw new ArgumentNullException("container"); - _container = container; - _typeCache = new ConcurrentDictionary(StringComparer.InvariantCultureIgnoreCase); - _system = system; - _system.AddDependencyResolver(this); -} -``` - -You have defined three private fields - -* ```IWindsorContainer _container``` is a reference to the CastleWindsor container. -* ```ConcurrentDictionary _typeCache``` is a thread safe map that contains actor name/type associations. -* ```ActorSystem _system``` is a reference to the ActorSystem. - -First you need to implement ```GetType```. This is a basic implementation and is just for demonstration purposes. Essentially this is used by the extension to get the type of the actor from it's type name. - -```csharp -public Type GetType(string actorName) -{ - _typeCache. - TryAdd(actorName, - actorName.GetTypeValue() ?? - _container.Kernel - .GetAssignableHandlers(typeof(object)) - .Where(handler => handler.ComponentModel.Name.Equals(actorName, StringComparison.InvariantCultureIgnoreCase)) - .Select(handler => handler.ComponentModel.Implementation) - .FirstOrDefault()); - - return _typeCache[actorName]; -} -``` - -Secondly you need to implement the ```CreateActorFactory``` method which will be used by the extension to create the actor. This implementation will depend upon the API of the container. - -```csharp -public Func CreateActorFactory(Type actorType) -{ - return () => (ActorBase)container.Resolve(actorType); -} -``` - -Thirdly, you implement the ```Create``` which is used register the ```Props``` configuration for the referenced actor type with the ```ActorSystem```. This method will always be the same implementation. - -```csharp -public Props Create() where TActor : ActorBase -{ - return system.GetExtension().Props(typeof(TActor).Name); -} -``` - -Lastly, you implement the Release method which in this instance is very simple. This method is used to remove the actor from the underlying container. - -```csharp -public void Release(ActorBase actor) -{ - this.container.Release(actor); -} -``` -**Note: For further details on the importance of the release method please read the following blog [post](http://blog.ploeh.dk/2014/05/19/di-friendly-framework/).** - -The resulting class should look similar to the following: - -```csharp -public class WindsorDependencyResolver : IDependencyResolver -{ - private IWindsorContainer container; - private ConcurrentDictionary typeCache; - private ActorSystem system; - - public WindsorDependencyResolver(IWindsorContainer container, ActorSystem system) - { - if (system == null) throw new ArgumentNullException("system"); - if (container == null) throw new ArgumentNullException("container"); - this.container = container; - typeCache = new ConcurrentDictionary(StringComparer.InvariantCultureIgnoreCase); - this.system = system; - this.system.AddDependencyResolver(this); - } - - public Type GetType(string actorName) - { - typeCache.TryAdd(actorName, actorName.GetTypeValue() ?? - container.Kernel - .GetAssignableHandlers(typeof(object)) - .Where(handler => handler.ComponentModel.Name.Equals(actorName, StringComparison.InvariantCultureIgnoreCase)) - .Select(handler => handler.ComponentModel.Implementation) - .FirstOrDefault()); - - return typeCache[actorName]; - } - - public Func CreateActorFactory(Type actorType) - { - return () => (ActorBase)container.Resolve(actorType); - } - - public Props Create() where TActor : ActorBase - { - return system.GetExtension().Props(typeof(TActor)); - } - - public void Release(ActorBase actor) - { - this.container.Release(actor); - } -} -``` - -Now, with the preceding class, you can do something like the following example: - -```csharp -// Setup CastleWindsor -IWindsorContainer container = new WindsorContainer(); -container.Register(Component.For().ImplementedBy()); -container.Register(Component.For().Named("TypedWorker").LifestyleTransient()); - -// Create the ActorSystem -using (var system = ActorSystem.Create("MySystem")) -{ - // Create the dependency resolver - IDependencyResolver resolver = new WindsorDependencyResolver(container, system); - - // Register the actors with the system - system.ActorOf(system.DI().Props(), "Worker1"); - system.ActorOf(system.DI().Props(), "Worker2"); - - // Create the router - IActorRef router = system.ActorOf(Props.Empty.WithRouter(new ConsistentHashingGroup(config))); - - // Create the message to send - TypedActorMessage message = new TypedActorMessage - { - Id = 1, - Name = Guid.NewGuid().ToString() - }; - - // Send the message to the router - router.Tell(message); -} -``` - -## Creating Child Actors using DI ## -When you want to create child actors from within your existing actors using Dependency Injection you can use the Actor Content extension just like in the following example. - -```csharp -Context.ActorOf(Context.DI().Props()).Tell(message); -``` diff --git a/src/contrib/dependencyinjection/Akka.DI.TestKit/Akka.DI.TestKit.csproj b/src/contrib/dependencyinjection/Akka.DI.TestKit/Akka.DI.TestKit.csproj deleted file mode 100644 index 17377f73ee8..00000000000 --- a/src/contrib/dependencyinjection/Akka.DI.TestKit/Akka.DI.TestKit.csproj +++ /dev/null @@ -1,30 +0,0 @@ - - - - - Akka.DI.TestKit - Dependency Injection (DI) TestKit support for Akka.NET - $(NetStandardLibVersion) - $(AkkaPackageTags);dependency injection;testkit - true - - - - - - - - - $(DefineConstants);RELEASE - - - - - - - - - - - - \ No newline at end of file diff --git a/src/contrib/dependencyinjection/Akka.DI.TestKit/DiResolverSpec.cs b/src/contrib/dependencyinjection/Akka.DI.TestKit/DiResolverSpec.cs deleted file mode 100644 index c110d9a003d..00000000000 --- a/src/contrib/dependencyinjection/Akka.DI.TestKit/DiResolverSpec.cs +++ /dev/null @@ -1,411 +0,0 @@ -//----------------------------------------------------------------------- -// -// Copyright (C) 2009-2021 Lightbend Inc. -// Copyright (C) 2013-2021 .NET Foundation -// -//----------------------------------------------------------------------- - -using System; -using System.Threading.Tasks; -using Akka.Actor; -using Akka.Configuration; -using Akka.DI.Core; -using Akka.Dispatch; -using Akka.Dispatch.MessageQueues; -using Akka.TestKit; -using Akka.TestKit.TestActors; -using Akka.TestKit.Xunit2; -using Akka.Util; -using Akka.Util.Internal; -using Xunit; - -namespace Akka.DI.TestKit -{ - public abstract class DiResolverSpec : TestKitBase, IDisposable - { - #region DI classes - - class GetCallCount { } - - class DiPerRequestActor : ReceiveActor - { - private readonly IDiTest _di; - - public DiPerRequestActor(IDiTest di) - { - _di = di; - - Receive(count => Sender.Tell(_di.CallCount)); - ReceiveAny(o => _di.Call()); - } - } - - class DiSingletonActor : ReceiveActor - { - private readonly IDiSingleton _di; - - public DiSingletonActor(IDiSingleton di) - { - _di = di; - - Receive(count => Sender.Tell(_di.CallCount)); - ReceiveAny(o => _di.Call()); - } - } - - class DiParentActor : ReceiveActor - { - private IActorRef _child; - - public class GetChild { } - - public DiParentActor() - { - Receive(c => Sender.Tell(_child)); - } - - protected override void PreStart() - { - var childProps = Context.DI().Props(); - _child = Context.ActorOf(childProps); - } - } - - class DisposableActor : ReceiveActor - { - public class Restart { } - - public class GetHashCode { } - - private readonly IDiDisposable _di; - - public DisposableActor(IDiDisposable di) - { - _di = di; - - Receive(g => Sender.Tell(_di.GetHashCode())); - Receive(r => ForceRestart()); - } - - private void ForceRestart() - { - throw new Exception("RESTART ME!"); - } - } - - interface IDiTest - { - int CallCount { get; } - - void Call(); - } - - class ConcreteDiTest : IDiTest - { - public int CallCount { get; private set; } - - public void Call() - { - CallCount = CallCount + 1; - } - } - - interface IDiSingleton - { - int CallCount { get; } - - void Call(); - } - - class ConcreteDiSingleton : IDiSingleton - { - AtomicCounter _counter = new AtomicCounter(0); - public int CallCount { get { return _counter.Current; }} - - public void Call() - { - _counter.GetAndIncrement(); - } - } - - interface IDiDisposable : IDisposable - { - bool WasDisposed { get; } - } - - class ConcreteDiDisposable : IDiDisposable - { - private readonly AtomicCounter _disposeCounter; - - public ConcreteDiDisposable(AtomicCounter disposeCounter) - { - _disposeCounter = disposeCounter; - } - - public void Dispose() - { - GC.SuppressFinalize(this); - Dispose(true); - } - - private void Dispose(bool isDisposing) - { - if (!WasDisposed) - { - WasDisposed = true; - _disposeCounter.Next(); - } - } - - - public bool WasDisposed { get; private set; } - } - - private static readonly IDiSingleton Single = new ConcreteDiSingleton(); - - class UnboundedStashActor : BlackHoleActor, IWithUnboundedStash - { - private readonly IDiTest _di; - - public UnboundedStashActor(IDiTest di) - { - _di = di; - } - - public IStash Stash { get; set; } - } - - class BoundedStashActor : BlackHoleActor, IWithBoundedStash - { - private readonly IDiTest _di; - - public BoundedStashActor(IDiTest di) - { - _di = di; - } - - public IStash Stash { get; set; } - } - - #endregion - - private static readonly AtomicCounter Counter = new AtomicCounter(0); - private string _pid; - - protected int ActorInstanceId = 1; - - public string Pid { get { return _pid; } } - - private AtomicCounter _disposeCounter = new AtomicCounter(0); - - protected DiResolverSpec(Config config = null, string actorSystemName = null, string testActorName = null) - : base(new XunitAssertions(), config, actorSystemName, testActorName) - { - _pid = "p-" + Counter.IncrementAndGet(); -// ReSharper disable once DoNotCallOverridableMethodsInConstructor - var resolver = ConfigureDependencyResolver(Sys); - } - - /// - /// Creates and configures a brand new . - /// - /// A new configured using the provided DI generator. - protected IDependencyResolver ConfigureDependencyResolver(ActorSystem system) - { - var container = NewDiContainer(); - Bind(container, () => new ConcreteDiTest()); - Bind(container, () => Single); - Bind(container, () => new ConcreteDiDisposable(_disposeCounter)); - Bind(container); - Bind(container); - Bind(container); - Bind(container); - Bind(container); - return NewDependencyResolver(container, system); - } - - #region Abstract methods - - /// - /// Create a new instance of the Dependency Injection container that we're creating. - /// - /// A new DI container instance. - protected abstract object NewDiContainer(); - - /// - /// Create a new instance that we're going to use - /// in the context of all of our tests. - /// - /// An instance. - protected abstract IDependencyResolver NewDependencyResolver(object diContainer, ActorSystem system); - - /// - /// Create a binding for type on the provided DI container. - /// - /// The type we're binding onto the DI container. - /// The DI container. - /// A generator function that yields new objects of type . - protected abstract void Bind(object diContainer, Func generator); - - /// - /// Create a binding for type on the provided DI container. - /// - /// Used for DI frameworks that require the DI target to be registered as well - /// as the injected components. - /// - /// The type we're binding onto the DI container. - /// The DI container. - protected abstract void Bind(object diContainer); - - #endregion - - #region Tests - - [Fact] - public void DependencyResolver_should_inject_new_instances_into_DiPerRequestActor() - { - var diActorProps = Sys.DI().Props(); - var diActor1 = Sys.ActorOf(diActorProps); - var diActor2 = Sys.ActorOf(diActorProps); - - diActor1.Tell("increment 1"); - diActor1.Tell("increment 2"); - diActor2.Tell("increment 1"); - - diActor1.Tell(new GetCallCount()); - Assert.Equal(2, ExpectMsg()); - - diActor2.Tell(new GetCallCount()); - Assert.Equal(1, ExpectMsg()); - } - - [Fact] - public void DependencyResolver_should_inject_new_instances_on_Restart() - { - var disposableActorProps = Sys.DI().Props(); - var disposableActor = Sys.ActorOf(disposableActorProps); - - disposableActor.Tell(new DisposableActor.GetHashCode()); - var originalHashCode = ExpectMsg(); - disposableActor.Tell(new DisposableActor.Restart()); - disposableActor.Tell(new DisposableActor.GetHashCode()); - var nextHashCode = ExpectMsg(); - Assert.NotEqual(originalHashCode, nextHashCode); - } - - [Fact] - public void DependencyResolver_should_inject_same_instance_into_DiSingletonActor() - { - var diActorProps = Sys.DI().Props(); - var diActor1 = Sys.ActorOf(diActorProps); - var diActor2 = Sys.ActorOf(diActorProps); - - diActor1.Tell("increment 1"); - diActor1.Tell("increment 2"); - diActor2.Tell("increment 1"); - - diActor1.Tell(new Identify(null)); - diActor2.Tell(new Identify(null)); - ExpectMsg(); - ExpectMsg(); - - diActor1.Tell(new GetCallCount()); - Assert.Equal(3, ExpectMsg()); - - diActor2.Tell(new GetCallCount()); - Assert.Equal(3, ExpectMsg()); - } - - [Fact] - public void DependencyResolver_should_inject_instances_into_DiChildActor() - { - var diParent = Sys.ActorOf(Props.Create()); - diParent.Tell(new DiParentActor.GetChild()); - var child = ExpectMsg(); - - child.Tell("increment 1"); - child.Tell("increment 2"); - - child.Tell(new GetCallCount()); - Assert.Equal(2, ExpectMsg()); - } - - [Fact] - public void DependencyResolver_should_inject_into_normal_mailbox_Actor() - { - var stashActorProps = Sys.DI().Props(); - var stashActor = Sys.ActorOf(stashActorProps); - - var internalRef = (RepointableActorRef)stashActor; - AwaitCondition(() => internalRef.IsStarted); - - Assert.IsType(internalRef.Underlying.AsInstanceOf().Mailbox.MessageQueue); - } - - [Fact] - public void DependencyResolver_should_inject_into_UnboundedStash_Actor() - { - var stashActorProps = Sys.DI().Props(); - var stashActor = Sys.ActorOf(stashActorProps); - - var internalRef = (RepointableActorRef)stashActor; - AwaitCondition(() => internalRef.IsStarted); - - Assert.IsType(internalRef.Underlying.AsInstanceOf().Mailbox.MessageQueue); - } - - [Fact] - public void DependencyResolver_should_inject_into_BoundedStash_Actor() - { - var stashActorProps = Sys.DI().Props(); - var stashActor = Sys.ActorOf(stashActorProps); - - var internalRef = (RepointableActorRef)stashActor; - AwaitCondition(() => internalRef.IsStarted); - - Assert.IsType(internalRef.Underlying.AsInstanceOf().Mailbox.MessageQueue); - } - - [Fact] - public void DependencyResolver_should_dispose_IDisposable_instances_on_Actor_Termination() - { - var disposableActorProps = Sys.DI().Props(); - var disposableActor = Sys.ActorOf(disposableActorProps); - - var currentDisposeCounter = _disposeCounter.Current; - Assert.True(disposableActor.GracefulStop(TimeSpan.FromSeconds(1)).Result); - AwaitAssert(() => Assert.True(currentDisposeCounter + 1 == _disposeCounter.Current), TimeSpan.FromSeconds(2), TimeSpan.FromMilliseconds(50)); - } - - [Fact] - public void DependencyResolver_should_dispose_IDisposable_instances_on_Actor_Restart() - { - var disposableActorProps = Sys.DI().Props(); - var disposableActor = Sys.ActorOf(disposableActorProps); - - var currentDisposeCounter = _disposeCounter.Current; - disposableActor.Tell(new DisposableActor.Restart()); - AwaitAssert(() => Assert.True(currentDisposeCounter + 1 == _disposeCounter.Current), TimeSpan.FromSeconds(2), TimeSpan.FromMilliseconds(50)); - } - - #endregion - - - public void Dispose() - { - Dispose(true); - GC.SuppressFinalize(this); - } - - /// Performs application-defined tasks associated with freeing, releasing, or resetting unmanaged resources. - /// if set to true the method has been called directly or indirectly by a - /// user's code. Managed and unmanaged resources will be disposed.
- /// if set to false the method has been called by the runtime from inside the finalizer and only - /// unmanaged resources can be disposed. - protected virtual void Dispose(bool disposing) - { - if (disposing) - Shutdown(); - } - } -} diff --git a/src/contrib/dependencyinjection/Akka.DI.TestKit/Properties/AssemblyInfo.cs b/src/contrib/dependencyinjection/Akka.DI.TestKit/Properties/AssemblyInfo.cs deleted file mode 100644 index 718fd87f534..00000000000 --- a/src/contrib/dependencyinjection/Akka.DI.TestKit/Properties/AssemblyInfo.cs +++ /dev/null @@ -1,22 +0,0 @@ -//----------------------------------------------------------------------- -// -// Copyright (C) 2009-2021 Lightbend Inc. -// Copyright (C) 2013-2021 .NET Foundation -// -//----------------------------------------------------------------------- - -using System.Reflection; -using System.Runtime.CompilerServices; -using System.Runtime.InteropServices; - -// General Information about an assembly is controlled through the following -// set of attributes. Change these attribute values to modify the information -// associated with an assembly. - -// Setting ComVisible to false makes the types in this assembly not visible -// to COM components. If you need to access a type in this assembly from -// COM, set the ComVisible attribute to true on that type. -[assembly: ComVisible(false)] - -// The following GUID is for the ID of the typelib if this project is exposed to COM -[assembly: Guid("411161b8-7246-4d19-85ee-eaddb63133b4")]