Skip to content

Commit

Permalink
DI support for cluster configuration and Actors
Browse files Browse the repository at this point in the history
  • Loading branch information
yevhen committed Aug 9, 2017
1 parent 8f7c73c commit ff7bdd7
Show file tree
Hide file tree
Showing 27 changed files with 844 additions and 76 deletions.
13 changes: 11 additions & 2 deletions Orleankka.sln
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio 14
VisualStudioVersion = 14.0.25420.1
# Visual Studio 15
VisualStudioVersion = 15.0.26430.16
MinimumVisualStudioVersion = 10.0.40219.1
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = ".paket", ".paket", "{E98080C8-5319-4686-BB1C-85413DEDB917}"
ProjectSection(SolutionItems) = preProject
Expand Down Expand Up @@ -125,6 +125,8 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ProtoBuf", "Source\Example.
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Hyperion", "Source\Example.Serialization.Hyperion\Hyperion.csproj", "{E43D9F8D-8EC8-44D3-A334-29B3655B022E}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Native", "Source\Example.DependencyInjection.Native\Native.csproj", "{6B9C3DE4-2F1E-4ABB-AE36-16D4811B172D}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Expand Down Expand Up @@ -378,6 +380,12 @@ Global
{E43D9F8D-8EC8-44D3-A334-29B3655B022E}.Package|Any CPU.Build.0 = Package|Any CPU
{E43D9F8D-8EC8-44D3-A334-29B3655B022E}.Release|Any CPU.ActiveCfg = Release|Any CPU
{E43D9F8D-8EC8-44D3-A334-29B3655B022E}.Release|Any CPU.Build.0 = Release|Any CPU
{6B9C3DE4-2F1E-4ABB-AE36-16D4811B172D}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{6B9C3DE4-2F1E-4ABB-AE36-16D4811B172D}.Debug|Any CPU.Build.0 = Debug|Any CPU
{6B9C3DE4-2F1E-4ABB-AE36-16D4811B172D}.Package|Any CPU.ActiveCfg = Release|Any CPU
{6B9C3DE4-2F1E-4ABB-AE36-16D4811B172D}.Package|Any CPU.Build.0 = Release|Any CPU
{6B9C3DE4-2F1E-4ABB-AE36-16D4811B172D}.Release|Any CPU.ActiveCfg = Release|Any CPU
{6B9C3DE4-2F1E-4ABB-AE36-16D4811B172D}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
Expand Down Expand Up @@ -431,5 +439,6 @@ Global
{2A3C4C8F-9836-4CE6-8089-08080463BAD1} = {C9B497F6-87DA-40EF-933C-A572A7603991}
{E43D9F8D-8EC8-44D3-A334-29B3677B022E} = {2A3C4C8F-9836-4CE6-8089-08080463BAD1}
{E43D9F8D-8EC8-44D3-A334-29B3655B022E} = {2A3C4C8F-9836-4CE6-8089-08080463BAD1}
{6B9C3DE4-2F1E-4ABB-AE36-16D4811B172D} = {85E741A4-D6F4-44C2-955B-F2FE10C0ECA5}
EndGlobalSection
EndGlobal
2 changes: 1 addition & 1 deletion Source/Demo.App.Tests/ApiFixture.cs
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ public override void SetUp()
worker = new MockApiWorker();
observers = new ObserverCollectionMock();

api = new Api("facebook", Runtime, observers, worker);
api = new Api(observers, worker, Runtime);
}

[Test]
Expand Down
9 changes: 1 addition & 8 deletions Source/Demo.App.Tests/TopicFixture.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,13 +24,6 @@ public class TopicFixture : ActorFixture
ActorRefMock facebook;
ActorRefMock twitter;

[TestFixtureSetUp]
public void FixtureSetUp()
{
// TODO: Fixit
//SerializationManager.InitializeForTesting();
}

[SetUp]
public override void SetUp()
{
Expand All @@ -45,7 +38,7 @@ public override void SetUp()
{twitter, TimeSpan.FromMinutes(5)},
};

topic = new Topic("42", Runtime, new TopicStorageMock());
topic = new Topic(new TopicStorageMock(), "42", Runtime);
}

[Test]
Expand Down
9 changes: 4 additions & 5 deletions Source/Demo.App/Api.cs
Original file line number Diff line number Diff line change
Expand Up @@ -66,12 +66,11 @@ public class Api : Actor
int failures;
bool available = true;

public Api(
string id,
IActorRuntime runtime,
public Api(
IObserverCollection observers,
IApiWorker worker)
: base(id, runtime)
IApiWorker worker,
IActorRuntime runtime = null)
: base(runtime)
{
this.observers = observers;
this.worker = worker;
Expand Down
2 changes: 1 addition & 1 deletion Source/Demo.App/ApiWorker.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ static class ApiWorkerFactory

abstract class ApiWorkerBase : IApiWorker
{
public string EndPoint { get; private set; }
public string EndPoint { get; }

protected ApiWorkerBase(string endPoint)
{
Expand Down
10 changes: 2 additions & 8 deletions Source/Demo.App/DI.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,18 +23,12 @@ public async Task Init(Options options)
public Actor Activate(Type type, string id, IActorRuntime runtime, Dispatcher dispatcher)
{
if (type == typeof(Api))
return CreateApi(id, runtime);
return new Api(new ObserverCollection(), ApiWorkerFactory.Create(id));

if (type == typeof(Topic))
return CreateTopic(id, runtime);
return new Topic(storage);

throw new InvalidOperationException($"Unknown actor type: {type}");
}

static Api CreateApi(string id, IActorRuntime runtime) =>
new Api(id, runtime, new ObserverCollection(), ApiWorkerFactory.Create(id));

Topic CreateTopic(string id, IActorRuntime runtime) =>
new Topic(id, runtime, storage);
}
}
5 changes: 4 additions & 1 deletion Source/Demo.App/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
using Orleankka.Utility;

using Microsoft.WindowsAzure.Storage;
using Microsoft.Extensions.DependencyInjection;

namespace Demo
{
Expand All @@ -29,7 +30,9 @@ public static void Main()
{
system = ActorSystem.Configure()
.Playground()
.Cluster(x => x.Activator(activator))
.Cluster(c => c
.Services(s => s
.AddSingleton<IActorActivator>(activator)))
.Assemblies(typeof(Api).Assembly)
.Done();

Expand Down
2 changes: 1 addition & 1 deletion Source/Demo.App/Topic.cs
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ public class Topic : Actor
internal int total;
string query;

public Topic(string id, IActorRuntime runtime, ITopicStorage storage)
public Topic(ITopicStorage storage, string id = null, IActorRuntime runtime = null)
: base(id, runtime)
{
this.storage = storage;
Expand Down
3 changes: 1 addition & 2 deletions Source/Example.DependencyInjection.Autofac/Actor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,7 @@ public class DIActor : Actor
{
readonly ISomeService service;

public DIActor(string id, IActorRuntime runtime, ISomeService service)
: base(id, runtime)
public DIActor(ISomeService service)
{
this.service = service;
}
Expand Down
5 changes: 4 additions & 1 deletion Source/Example.DependencyInjection.Autofac/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
using System.Threading.Tasks;

using Autofac;
using Microsoft.Extensions.DependencyInjection;

using Orleankka;
using Orleankka.Playground;
Expand Down Expand Up @@ -30,7 +31,9 @@ public static void Main()
var system = ActorSystem
.Configure()
.Playground()
.Cluster(x => x.Activator(new AutofacActorActivator(setup)))
.Cluster(c => c
.Services(s => s
.AddSingleton<IActorActivator>(new AutofacActorActivator(setup))))
.Assemblies(Assembly.GetExecutingAssembly())
.Done();

Expand Down
20 changes: 20 additions & 0 deletions Source/Example.DependencyInjection.Native/Actor.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
using Orleankka;

namespace Example
{
public class DIActor : Actor
{
readonly ISomeService service;

public DIActor(ISomeService service)
: base("id", null)
{
this.service = service;
}

public void Handle(string msg)
{
service.SayHello(msg, Self);
}
}
}
76 changes: 76 additions & 0 deletions Source/Example.DependencyInjection.Native/App.config
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<configSections>
<sectionGroup name="applicationSettings" type="System.Configuration.ApplicationSettingsGroup, System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
<section name="Example.Properties.Settings" type="System.Configuration.ClientSettingsSection, System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" requirePermission="false" />
</sectionGroup>
</configSections>
<applicationSettings>
<Example.Properties.Settings>
<setting name="ConnectionString" serializeAs="String">
<value>Account=SomeConfigurationValue</value>
</setting>
</Example.Properties.Settings>
</applicationSettings>
<runtime>
<gcServer enabled="true" />
<gcConcurrent enabled="false" />

<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
<dependentAssembly>
<Paket>True</Paket>
<assemblyIdentity name="Microsoft.CodeAnalysis" publicKeyToken="31bf3856ad364e35" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-65535.65535.65535.65535" newVersion="2.2.0.0" />
</dependentAssembly>
<dependentAssembly>
<Paket>True</Paket>
<assemblyIdentity name="Microsoft.CodeAnalysis.CSharp" publicKeyToken="31bf3856ad364e35" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-65535.65535.65535.65535" newVersion="2.2.0.0" />
</dependentAssembly>
<dependentAssembly>
<Paket>True</Paket>
<assemblyIdentity name="System.Collections.Immutable" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-65535.65535.65535.65535" newVersion="1.2.1.0" />
</dependentAssembly>
<dependentAssembly>
<Paket>True</Paket>
<assemblyIdentity name="System.Diagnostics.FileVersionInfo" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-65535.65535.65535.65535" newVersion="4.0.1.0" />
</dependentAssembly>
<dependentAssembly>
<Paket>True</Paket>
<assemblyIdentity name="System.IO.Compression" publicKeyToken="b77a5c561934e089" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-65535.65535.65535.65535" newVersion="4.1.2.0" />
</dependentAssembly>
<dependentAssembly>
<Paket>True</Paket>
<assemblyIdentity name="System.IO.FileSystem" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-65535.65535.65535.65535" newVersion="4.0.2.0" />
</dependentAssembly>
<dependentAssembly>
<Paket>True</Paket>
<assemblyIdentity name="System.IO.FileSystem.Primitives" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-65535.65535.65535.65535" newVersion="4.0.2.0" />
</dependentAssembly>
<dependentAssembly>
<Paket>True</Paket>
<assemblyIdentity name="System.Security.Cryptography.Algorithms" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-65535.65535.65535.65535" newVersion="4.1.0.0" />
</dependentAssembly>
<dependentAssembly>
<Paket>True</Paket>
<assemblyIdentity name="System.Security.Cryptography.Primitives" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-65535.65535.65535.65535" newVersion="4.0.1.0" />
</dependentAssembly>
<dependentAssembly>
<Paket>True</Paket>
<assemblyIdentity name="System.ValueTuple" publicKeyToken="cc7b13ffcd2ddd51" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-65535.65535.65535.65535" newVersion="4.0.1.1" />
</dependentAssembly>
<dependentAssembly>
<Paket>True</Paket>
<assemblyIdentity name="System.Xml.XPath.XDocument" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-65535.65535.65535.65535" newVersion="4.0.2.0" />
</dependentAssembly>
</assemblyBinding></runtime>
</configuration>
Loading

0 comments on commit ff7bdd7

Please sign in to comment.