Skip to content

Commit

Permalink
Update README.md and LICENSE
Browse files Browse the repository at this point in the history
  • Loading branch information
uurha committed Feb 10, 2024
0 parents commit f63bc02
Show file tree
Hide file tree
Showing 18 changed files with 327 additions and 0 deletions.
8 changes: 8 additions & 0 deletions Editor.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

18 changes: 18 additions & 0 deletions Editor/BetterServices.Editor.asmdef
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
{
"name": "BetterServices.Editor",
"rootNamespace": "Better.Services",
"references": [
"GUID:1c5574afb40e5fe4ca9e9c156009297b"
],
"includePlatforms": [
"Editor"
],
"excludePlatforms": [],
"allowUnsafeCode": false,
"overrideReferences": false,
"precompiledReferences": [],
"autoReferenced": true,
"defineConstraints": [],
"versionDefines": [],
"noEngineReferences": false
}
7 changes: 7 additions & 0 deletions Editor/BetterServices.Editor.asmdef.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

21 changes: 21 additions & 0 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
MIT License

Copyright (c) 2022 Arcueid D'athemon (https://github.com/uurha)

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
5 changes: 5 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# Better Services
This plugins provides basic implementation for services pattern

## Install
[How to install](https://github.com/uurha/BetterPluginCollection/wiki/How-to-install)
8 changes: 8 additions & 0 deletions Runtime.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

17 changes: 17 additions & 0 deletions Runtime/BetterServices.Runtime.asmdef
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
{
"name": "BetterServices.Runtime",
"rootNamespace": "Better.Services",
"references": [
"GUID:441b78e90a9cf724ab41c6eed8c0b93d",
"GUID:a59e3daedde9ca94bba45364d4ead25f"
],
"includePlatforms": [],
"excludePlatforms": [],
"allowUnsafeCode": false,
"overrideReferences": false,
"precompiledReferences": [],
"autoReferenced": true,
"defineConstraints": [],
"versionDefines": [],
"noEngineReferences": false
}
7 changes: 7 additions & 0 deletions Runtime/BetterServices.Runtime.asmdef.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 8 additions & 0 deletions Runtime/Interfaces.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

14 changes: 14 additions & 0 deletions Runtime/Interfaces/IService.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
using System.Threading;
using System.Threading.Tasks;

namespace Better.Services.Runtime.Interfaces
{
public interface IService
{
public bool Initialized { get; }

public Task InitializeAsync(CancellationToken cancellationToken);

public Task PostInitializeAsync(CancellationToken cancellationToken);
}
}
11 changes: 11 additions & 0 deletions Runtime/Interfaces/IService.cs.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 8 additions & 0 deletions Runtime/Services.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

67 changes: 67 additions & 0 deletions Runtime/Services/MonoService.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
using System.Threading;
using System.Threading.Tasks;
using Better.Services.Runtime.Interfaces;
using UnityEngine;

namespace Better.Services.Runtime
{
public abstract class MonoService : MonoBehaviour, IService
{
// TODO: Add version dependency
private CancellationTokenSource _destroyCancellationToken;

public bool Initialized { get; private set; }
protected CancellationToken DestroyCancellationToken => _destroyCancellationToken.Token;

protected virtual void Awake()
{
_destroyCancellationToken = new();
}

async Task IService.InitializeAsync(CancellationToken cancellationToken)
{
Debug.Log($"[{GetType().Name}] {nameof(IService.InitializeAsync)}");

if (Initialized)
{
Debug.LogError($"[{GetType().Name}] {nameof(IService.InitializeAsync)}: already initialized");
return;
}

var linkedTokenSource = CancellationTokenSource.CreateLinkedTokenSource(DestroyCancellationToken, cancellationToken);
cancellationToken = linkedTokenSource.Token;

await OnInitializeAsync(cancellationToken);
if (cancellationToken.IsCancellationRequested)
{
return;
}

Initialized = true;
}

Task IService.PostInitializeAsync(CancellationToken cancellationToken)
{
if (!Initialized)
{
Debug.LogError($"[{GetType().Name}] {nameof(IService.PostInitializeAsync)}: not initialized");
return Task.CompletedTask;
}

Debug.Log($"[{GetType().Name}] {nameof(IService.PostInitializeAsync)}");

var linkedTokenSource = CancellationTokenSource.CreateLinkedTokenSource(DestroyCancellationToken, cancellationToken);
cancellationToken = linkedTokenSource.Token;

return OnPostInitializeAsync(cancellationToken);
}

protected abstract Task OnInitializeAsync(CancellationToken cancellationToken);
protected abstract Task OnPostInitializeAsync(CancellationToken cancellationToken);

protected virtual void OnDestroy()
{
_destroyCancellationToken?.Cancel();
}
}
}
11 changes: 11 additions & 0 deletions Runtime/Services/MonoService.cs.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

68 changes: 68 additions & 0 deletions Runtime/Services/PocoService.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
using System;
using System.Threading;
using System.Threading.Tasks;
using Better.Services.Runtime.Interfaces;
using Better.Validation.Runtime.Attributes;
using UnityEngine;

namespace Better.Services.Runtime
{
[Serializable]
public abstract class PocoService : IService
{
public bool Initialized { get; private set; }

async Task IService.InitializeAsync(CancellationToken cancellationToken)
{
Debug.Log($"[{GetType().Name}] {nameof(IService.InitializeAsync)}");

if (Initialized)
{
Debug.LogError($"[{GetType().Name}] {nameof(IService.InitializeAsync)}: already initialized");
return;
}

Initialized = true;
await OnInitializeAsync(cancellationToken);
Initialized = !cancellationToken.IsCancellationRequested;
}

Task IService.PostInitializeAsync(CancellationToken cancellationToken)
{
if (!Initialized)
{
Debug.LogError($"[{GetType().Name}] {nameof(IService.PostInitializeAsync)}: not initialized");
return Task.CompletedTask;
}

Debug.Log($"[{GetType().Name}] {nameof(IService.PostInitializeAsync)}");
return OnPostInitializeAsync(cancellationToken);
}

protected abstract Task OnInitializeAsync(CancellationToken cancellationToken);
protected abstract Task OnPostInitializeAsync(CancellationToken cancellationToken);
}

[Serializable]
public abstract class PocoService<TSettings> : PocoService where TSettings : ScriptableObject
{
[NotNull] [SerializeField] private TSettings _settings;

protected TSettings Settings => _settings;

protected override Task OnInitializeAsync(CancellationToken cancellationToken)
{
if (Settings == null)
{
throw new NullReferenceException($"[{GetType().Name}] {nameof(OnInitializeAsync)}: {nameof(Settings)} cannot be null");
}

return Task.CompletedTask;
}

protected override Task OnPostInitializeAsync(CancellationToken cancellationToken)
{
return Task.CompletedTask;
}
}
}
11 changes: 11 additions & 0 deletions Runtime/Services/PocoService.cs.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

31 changes: 31 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
{
"name": "com.tdw.betterservices",
"displayName": "Better Services",
"version": "0.0.1",
"unity": "2021.3",
"description": " ",
"dependencies": {
"com.uurha.bettervalidation": "1.0.55"
},
"author": {
"name": "Techno Dwarf Works",
"url": "https://github.com/techno-dwarf-works"
},
"changelogUrl": "https://github.com/techno-dwarf-works/better-services",
"documentationUrl": "https://github.com/techno-dwarf-works/better-services/tree/main#readme",
"license": "MIT",
"licensesUrl":"https://github.com/techno-dwarf-works/better-services/blob/main/LICENSE",
"keywords": [
"better",
"services",
"reference managment",
"pattern"
],
"samples": [
{
"displayName": "Default samples",
"description": "Contains test samples",
"path": "Samples~/TestSamples"
}
]
}
7 changes: 7 additions & 0 deletions package.json.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit f63bc02

Please sign in to comment.