Skip to content

Commit

Permalink
Make forgettable unitask can be handled via each LifetimeScopes
Browse files Browse the repository at this point in the history
  • Loading branch information
hadashiA committed Jan 30, 2021
1 parent 53ddd5e commit 8d50568
Show file tree
Hide file tree
Showing 35 changed files with 452 additions and 396 deletions.
3 changes: 3 additions & 0 deletions VContainer/Assets/VContainer/Runtime/Interfaces.meta

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

12 changes: 12 additions & 0 deletions VContainer/Assets/VContainer/Runtime/Interfaces/IAsyncStartable.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
#if VCONTAINER_UNITASK_INTEGRATION
using System.Threading;
using Cysharp.Threading.Tasks;

namespace VContainer.Unity
{
public interface IAsyncStartable
{
UniTask StartAsync(CancellationToken cancellation);
}
}
#endif

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

Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
namespace VContainer.Unity
{
public interface IFixedTickable
{
void FixedTick();
}
}

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

Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
namespace VContainer.Unity
{
public interface IInitializable
{
void Initialize();
}
}

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

Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
namespace VContainer.Unity
{
public interface ILateTickable
{
void LateTick();
}
}

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

Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
namespace VContainer.Unity
{
public interface IPostFixedTickable
{
void PostFixedTick();
}
}

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

Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
namespace VContainer.Unity
{
public interface IPostInitializable
{
void PostInitialize();
}
}

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

Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
namespace VContainer.Unity
{
public interface IPostLateTickable
{
void PostLateTick();
}
}

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

Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
namespace VContainer.Unity
{
public interface IPostStartable
{
void PostStart();
}
}

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

Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
namespace VContainer.Unity
{
public interface IPostTickable
{
void PostTick();
}
}

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

7 changes: 7 additions & 0 deletions VContainer/Assets/VContainer/Runtime/Interfaces/IStartable.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
namespace VContainer.Unity
{
public interface IStartable
{
void Start();
}
}

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

7 changes: 7 additions & 0 deletions VContainer/Assets/VContainer/Runtime/Interfaces/ITickable.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
namespace VContainer.Unity
{
public interface ITickable
{
void Tick();
}
}

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

Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
using System;
using UnityEngine;
using VContainer.Internal;
using VContainer.Runtime.Unity;

#if VCONTAINER_ECS_INTEGRATION
using Unity.Entities;
#endif
Expand All @@ -20,6 +22,9 @@ public EntryPointsBuilder(IContainerBuilder containerBuilder, Lifetime lifetime)

public RegistrationBuilder Add<T>()
=> containerBuilder.Register<T>(lifetime).AsImplementedInterfaces();

public void OnStartUpException(Action<Exception> exceptionHandler)
=> containerBuilder.RegisterStartupExceptionHandler(exceptionHandler);
}

public readonly struct ComponentsBuilder
Expand Down Expand Up @@ -57,6 +62,13 @@ public static void UseEntryPoints(
configuration(entryPoints);
}

public static void RegisterStartupExceptionHandler(
this IContainerBuilder builder,
Action<Exception> exceptionHandler)
{
builder.RegisterInstance(new StartupExceptionHandler(exceptionHandler));
}

public static void UseComponents(this IContainerBuilder builder, Action<ComponentsBuilder> configuration)
{
var components = new ComponentsBuilder(builder);
Expand Down
18 changes: 14 additions & 4 deletions VContainer/Assets/VContainer/Runtime/Unity/LifetimeScope.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
using UnityEngine;
using UnityEngine.SceneManagement;
using VContainer.Internal;
using VContainer.Runtime.Unity;

#if VCONTAINER_ECS_INTEGRATION
using Unity.Entities;
Expand Down Expand Up @@ -288,6 +289,15 @@ void ActivateEntryPoints()
{
PlayerLoopHelper.Initialize();

StartupExceptionHandler exceptionHandler = null;
try
{
exceptionHandler = Container.Resolve<StartupExceptionHandler>();
}
catch (VContainerException ex) when (ex.InvalidType == typeof(StartupExceptionHandler))
{
}

var initializables = Container.Resolve<IReadOnlyList<IInitializable>>();
if (initializables.Count > 0)
{
Expand All @@ -299,23 +309,23 @@ void ActivateEntryPoints()
var postInitializables = Container.Resolve<IReadOnlyList<IPostInitializable>>();
if (postInitializables.Count > 0)
{
var loopItem = new PostInitializationLoopItem(postInitializables);
var loopItem = new PostInitializationLoopItem(postInitializables, exceptionHandler);
disposable.Add(loopItem);
PlayerLoopHelper.Dispatch(PlayerLoopTiming.PostInitialization, loopItem);
}

var startables = Container.Resolve<IReadOnlyList<IStartable>>();
if (startables.Count > 0)
{
var loopItem = new StartableLoopItem(startables);
var loopItem = new StartableLoopItem(startables, exceptionHandler);
disposable.Add(loopItem);
PlayerLoopHelper.Dispatch(PlayerLoopTiming.Startup, loopItem);
}

var postStartables = Container.Resolve<IReadOnlyList<IPostStartable>>();
if (postStartables.Count > 0)
{
var loopItem = new PostStartableLoopItem(postStartables);
var loopItem = new PostStartableLoopItem(postStartables, exceptionHandler);
disposable.Add(loopItem);
PlayerLoopHelper.Dispatch(PlayerLoopTiming.PostStartup, loopItem);
}
Expand Down Expand Up @@ -372,7 +382,7 @@ void ActivateEntryPoints()
var asyncStartables = Container.Resolve<IReadOnlyList<IAsyncStartable>>();
if (asyncStartables.Count > 0)
{
var loopItem = new AsyncStartableLoopItem(asyncStartables);
var loopItem = new AsyncStartableLoopItem(asyncStartables, exceptionHandler);
disposable.Add(loopItem);
PlayerLoopHelper.Dispatch(PlayerLoopTiming.Startup, loopItem);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,6 @@ static class PlayerLoopHelper
// [RuntimeInitializeOnLoadMethod(RuntimeInitializeLoadType.BeforeSceneLoad)]
public static void Initialize()
{
return;
lock (Runners)
{
if (initialized) return;
Expand Down
Loading

0 comments on commit 8d50568

Please sign in to comment.