Skip to content

Commit

Permalink
version 0.1.1-beta
Browse files Browse the repository at this point in the history
add prototype dependencies
  • Loading branch information
decembrist-revolt authored and decembrist-revolt committed Apr 26, 2021
1 parent be9b32c commit f48dfd2
Show file tree
Hide file tree
Showing 20 changed files with 398 additions and 107 deletions.
7 changes: 5 additions & 2 deletions Decembrist Plugin.csproj
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
<Project Sdk="Godot.NET.Sdk/3.2.3">
<Project Sdk="Godot.NET.Sdk/3.3.0">
<PropertyGroup>
<LangVersion>8</LangVersion>
<LangVersion>9</LangVersion>
<TargetFramework>netcoreapp3.1</TargetFramework>
<RootNamespace>Decembrist</RootNamespace>
</PropertyGroup>
<ItemGroup>
<Content Include="README.md" />
</ItemGroup>
</Project>
8 changes: 5 additions & 3 deletions Example/DecembristConfiguration.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,14 @@

namespace Decembrist.Example
{
public class DecembristConfiguration: IDecembristConfiguration
public class DecembristConfiguration : IDecembristConfiguration
{
public ContainerBuilder ConfigDi(ContainerBuilder builder)
{
builder.Register<SomeService2, IService>();
builder.Register<SomeService1>();
builder.RegisterInstance(InstanceService.Instance);
builder.Register<SingletonService2, IService>();
builder.Register<SingletonService1>();
builder.RegisterPrototype<PrototypeService1>();
return builder;
}
}
Expand Down
2 changes: 1 addition & 1 deletion Example/Service/IService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,6 @@
{
public interface IService
{
public void Run();
public string GetString();
}
}
12 changes: 12 additions & 0 deletions Example/Service/InstanceService.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
namespace Decembrist.Example.Service
{
public class InstanceService
{

public static InstanceService Instance = new InstanceService();

private InstanceService()
{
}
}
}
21 changes: 21 additions & 0 deletions Example/Service/PrototypeService1.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
using Decembrist.Utils;

namespace Decembrist.Example.Service
{
public class PrototypeService1: IService
{
private readonly SingletonService2 _service;
private readonly string _randomNumber;

public PrototypeService1(SingletonService2 service)
{
_service = service;
_randomNumber = Random.RandomInt(1, 100).ToString();
}

public string GetString()
{
return $"{_randomNumber} {_service.GetString()}";
}
}
}
9 changes: 9 additions & 0 deletions Example/Service/SingletonService1.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
using Godot;

namespace Decembrist.Example.Service
{
public class SingletonService1
{
public string SayHello() => "Hello";
}
}
14 changes: 14 additions & 0 deletions Example/Service/SingletonService2.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
namespace Decembrist.Example.Service
{
public class SingletonService2: IService
{
private readonly SingletonService1 _service1;

public SingletonService2(SingletonService1 service1)
{
_service1 = service1;
}

public string GetString() => _service1.SayHello();
}
}
9 changes: 0 additions & 9 deletions Example/Service/SomeService1.cs

This file was deleted.

14 changes: 0 additions & 14 deletions Example/Service/SomeService2.cs

This file was deleted.

56 changes: 54 additions & 2 deletions Example/TestScene.cs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
using System;
using Godot;
using Decembrist.Di;
using Decembrist.Example.Service;
Expand All @@ -8,12 +9,63 @@ namespace Decembrist.Example
public class TestScene : Node2D
{
[Inject]
private IService service;
private IService service1;

[Inject]
private IService service2;

[Inject]
private PrototypeService1 prototypeService1;

[Inject]
private PrototypeService1 prototypeService2;

[Inject]
private InstanceService instanceService;

public override void _Ready()
{
// init dependencies
var watch = new System.Diagnostics.Stopwatch();
watch.Start();
this.InjectAll();
service.Run();
watch.Stop();
GD.Print($"Injection time Time: {watch.ElapsedMilliseconds} ms");
GD.Print("Service assertions................................................");
AssertTrue(service1 != null, "singleton service exists");
AssertTrue(this.Resolve<IService>() != null, "singleton service exists");
AssertTrue(instanceService == InstanceService.Instance, "service is singleton");
AssertTrue(this.Resolve<IService>() == service1, "service is singleton");
AssertTrue(service1 == service2, "service is singleton");
AssertTrue(this.Resolve<PrototypeService1>() != null, "prototype service exists");
AssertTrue(this.Resolve<PrototypeService1>() != prototypeService1, "service is prototype");
AssertTrue(prototypeService1 != prototypeService2, "service is prototype");
GD.Print("Service test......................................................");
ServiceEcho();
}

private void ServiceEcho()
{
GD.Print($"singleton1 says {service1.GetString()}");
GD.Print($"singleton2 says {service2.GetString()}");
GD.Print($"resolved singleton says {this.Resolve<IService>().GetString()}");
GD.Print($"prototype1 says {prototypeService1.GetString()}");
GD.Print($"prototype2 says {prototypeService2.GetString()}");
GD.Print($"resolved prototype says {this.Resolve<PrototypeService1>().GetString()}");
}

private static void AssertTrue(bool expression, string test)
{
if (expression)
{
GD.Print($"PASSED:{test}");
}
else
{
var message = $"FAILED:{test}";
GD.PrintErr(message);
throw new Exception(message);
}
}

}
Expand Down
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
**Godot Decembrist Plugin**
_Utils for godot development_
* (DI) Dependency Injection for Godot
* Util classes for _Buttons_, _Controls_, _Vectors_ etc
Loading

0 comments on commit f48dfd2

Please sign in to comment.