update readme

This commit is contained in:
Mikhail 2026-03-29 01:49:14 +08:00
parent 1b3c009768
commit 431f0b873c
2 changed files with 57 additions and 17 deletions

View File

@ -81,7 +81,7 @@ https://github.com/DCFApixels/DragonECS-AutoInjections.git
# Интеграция # Интеграция
Добавьте вызов метода `AutoInject()` для Builder-а пайплайна. Пример: Добавьте вызов метода `AutoInject()` для Builder-а пайплайна. Пример:
```csharp ```c#
_pipeline = EcsPipeline.New() _pipeline = EcsPipeline.New()
.Inject(world) .Inject(world)
.Inject(_timeService) .Inject(_timeService)
@ -99,11 +99,11 @@ _pipeline = EcsPipeline.New()
# Инъекция зависимостей # Инъекция зависимостей
Атрибут `[DI]` заменяет интерфейс `IEcsInject<T>`, Поля, отмеченные этим атрибутом, автоматически получают зависимости, внедрённые в Pipeline. Пример: Атрибут `[DI]` заменяет интерфейс `IEcsInject<T>`, Поля, отмеченные этим атрибутом, автоматически получают зависимости, внедрённые в Pipeline. Пример:
```csharp ```c#
[DI] EcsDefaultWorld _world; [DI] EcsDefaultWorld _world;
``` ```
Так же можно делать внедрение через свойство или метод: Так же можно делать внедрение через свойство или метод:
```csharp ```c#
EcsDefaultWorld _world; EcsDefaultWorld _world;
//Обязательно наличие set блока. //Обязательно наличие set блока.
@ -137,7 +137,7 @@ EcsDefaultWorld _world;
# Auto Runner-ы # Auto Runner-ы
Для получения раннеров без добавления, есть атрибут `[BindWithRunner(type)]` и метод `GetRunnerAuto<T>()`. Для получения раннеров без добавления, есть атрибут `[BindWithRunner(type)]` и метод `GetRunnerAuto<T>()`.
``` c# ```c#
[BindWithRunner(typeof(DoSomethingProcessRunner))] [BindWithRunner(typeof(DoSomethingProcessRunner))]
interface IDoSomethingProcess : IEcsProcess interface IDoSomethingProcess : IEcsProcess
{ {
@ -161,7 +161,7 @@ _pipeline.GetRunnerAuto<IDoSomethingProcess>().Do();
# Пример кода # Пример кода
```csharp ```c#
class VelocitySystemDI : IEcsRun class VelocitySystemDI : IEcsRun
{ {
class Aspect : EcsAspectAuto class Aspect : EcsAspectAuto
@ -189,7 +189,7 @@ class VelocitySystemDI : IEcsRun
<details> <details>
<summary>Тот же код но без AutoInjections</summary> <summary>Тот же код но без AutoInjections</summary>
```csharp ```c#
class VelocitySystem : IEcsRun, IEcsInject<EcsDefaultWorld>, IEcsInject<TimeService> class VelocitySystem : IEcsRun, IEcsInject<EcsDefaultWorld>, IEcsInject<TimeService>
{ {
class Aspect : EcsAspect class Aspect : EcsAspect
@ -226,7 +226,7 @@ class VelocitySystem : IEcsRun, IEcsInject<EcsDefaultWorld>, IEcsInject<TimeServ
# Не null инъекции # Не null инъекции
Чтобы поле, отмеченное атрибутом `[DI]`, было проинициализировано даже в случае отсутствия инъекции, в конструктор атрибута можно передать тип-заглушку. В примере ниже поле `foo` получит экземпляр `Foo` из инъекции или экземпляр `FooDummy : Foo`, если инъекция не была выполнена. Чтобы поле, отмеченное атрибутом `[DI]`, было проинициализировано даже в случае отсутствия инъекции, в конструктор атрибута можно передать тип-заглушку. В примере ниже поле `foo` получит экземпляр `Foo` из инъекции или экземпляр `FooDummy : Foo`, если инъекция не была выполнена.
``` csharp ```c#
[DI(typeof(FooDummy))] Foo foo; [DI(typeof(FooDummy))] Foo foo;
``` ```
> Переданный тип должен иметь конструктор без параметров и быть либо того же типа, что и поле, либо производным от него. > Переданный тип должен иметь конструктор без параметров и быть либо того же типа, что и поле, либо производным от него.

View File

@ -45,31 +45,71 @@ The extension is designed to reduce the amount of code by simplifying dependency
</br> </br>
# Installation # Installation
Versioning semantics - [Open](https://gist.github.com/DCFApixels/e53281d4628b19fe5278f3e77a7da9e8#file-dcfapixels_versioning_ru-md) Versioning semantics - [Open](https://gist.github.com/DCFApixels/af79284955bf40e9476cdcac79d7b098#file-dcfapixels_versioning-md)
## Environment ## Environment
Requirements: Requirements:
+ Dependency: [DragonECS](https://github.com/DCFApixels/DragonECS) + Dependency: [DragonECS](https://github.com/DCFApixels/DragonECS)
+ Minimum version of C# 7.3; + Minimum version of C# 7.3;
Optional: Optional:
+ Game engines with C#: Unity, Godot, MonoGame, etc. * Game engines with C#: Unity, Godot, MonoGame, etc.
Tested with: Tested with:
+ **Unity:** Minimum version 2020.1.0; * **Unity:** Minimum version 2021.2.0.
## Unity Installation ## Unity Installation
* ### Unity Package * ### Unity Package
The package can be installed as a Unity package by adding the Git URL [in the PackageManager](https://docs.unity3d.com/2023.2/Documentation/Manual/upm-ui-giturl.html) or manually adding it to `Packages/manifest.json`: The package supports installation as a Unity package by adding the Git URL [in the PackageManager](https://docs.unity3d.com/2023.2/Documentation/Manual/upm-ui-giturl.html):
``` ```
https://github.com/DCFApixels/DragonECS-AutoInjections.git https://github.com/DCFApixels/DragonECS-AutoInjections.git
``` ```
Or add the package entry to `Packages/manifest.json`:
```
"com.dcfa_pixels.dragonecs-auto_injections": "https://github.com/DCFApixels/DragonECS-AutoInjections.git",
```
* ### Source Code * ### Source Code
The package can also be added to the project as source code. The package source code can also be copied directly into the project.
</br> </br>
# Integration
Add the AutoInject() call to the pipeline Builder. Example:
```c#
_pipeline = EcsPipeline.New()
.Inject(world)
.Inject(_timeService)
.Add(new TestSystem())
.Add(new VelocitySystem())
.Add(new ViewSystem())
.AutoInject() // Done — automatic injections enabled
.BuildAndInit();
```
> [!IMPORTANT]
> Ensure AutoInject() is called during initialization; otherwise nothing will work.
# Dependency Injection
The `[DI]` attribute replaces the `IEcsInject<T>` interface. Fields marked with this attribute automatically receive dependencies injected into the pipeline. Example
```c#
[DI] EcsDefaultWorld _world;
```
Injection can also be done via a property or method:
```c#
EcsDefaultWorld _world;
//Обязательно наличие set блока.
[DI] EcsDefaultWorld World { set => _world = value; }
//Количество аргументов должно быть равно 1.
[DI] void InjectWorld(EcsDefaultWorld world) => _world = world;
```
> Aggressive injection (without the `[DI]` attribute) is enabled by calling `.AutoInject(true)`.
# Code Example # Code Example
```csharp ```c#
class VelocitySystemDI : IEcsRun class VelocitySystemDI : IEcsRun
{ {
class Aspect : EcsAspectAuto class Aspect : EcsAspectAuto
@ -79,8 +119,8 @@ class VelocitySystemDI : IEcsRun
[Inc] public EcsPool<Velocity> velocities; [Inc] public EcsPool<Velocity> velocities;
} }
[EcsInject] EcsDefaultWorld _world; [DI] EcsDefaultWorld _world;
[EcsInject] TimeService _time; [DI] TimeService _time;
public void Run() public void Run()
{ {
@ -94,7 +134,7 @@ class VelocitySystemDI : IEcsRun
<details> <details>
<summary>Same code but without AutoInjections</summary> <summary>Same code but without AutoInjections</summary>
```csharp ```c#
class VelocitySystem : IEcsRun, IEcsInject<EcsDefaultWorld>, IEcsInject<TimeService> class VelocitySystem : IEcsRun, IEcsInject<EcsDefaultWorld>, IEcsInject<TimeService>
{ {
class Aspect : EcsAspect class Aspect : EcsAspect