Skip to content

Commit

Permalink
Merge pull request #32 from hadashiA/ku/improve-di
Browse files Browse the repository at this point in the history
Improve some  DI api
  • Loading branch information
hadashiA authored Jan 24, 2024
2 parents 62db340 + 021bb99 commit a62480b
Showing 1 changed file with 21 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -77,37 +77,46 @@ public RoutingBuilder(IContainerBuilder containerBuilder)
this.containerBuilder = containerBuilder;
}

public void Map<T>()
public RegistrationBuilder Map<T>()
{
RegistrationBuilder registrationBuilder;
if (typeof(UnityEngine.Component).IsAssignableFrom(typeof(T)))
{
containerBuilder.RegisterComponentOnNewGameObject(typeof(T), Lifetime.Singleton);
registrationBuilder = containerBuilder.RegisterComponentOnNewGameObject(typeof(T), Lifetime.Singleton);
}
else
{
containerBuilder.Register<T>(Lifetime.Singleton);
registrationBuilder = containerBuilder.Register<T>(Lifetime.Singleton);
}
MapRoutesInfos.Add(MapRoutesInfo.Analyze(typeof(T)));
return registrationBuilder;
}

public void Map<T>(T instance) where T : class
public RegistrationBuilder Map<T>(T instance) where T : class
{
containerBuilder.RegisterInstance(instance);
MapRoutesInfos.Add(MapRoutesInfo.Analyze(typeof(T)));
return containerBuilder.RegisterInstance(instance);
}

public void MapComponentInHierarchy<T>() where T : UnityEngine.Component
public RegistrationBuilder MapComponentInHierarchy<T>() where T : UnityEngine.Component
{
containerBuilder.RegisterComponentInHierarchy<T>();
MapRoutesInfos.Add(MapRoutesInfo.Analyze(typeof(T)));
return containerBuilder.RegisterComponentInHierarchy<T>();
}

public void MapComponentInNewPrefab<T>(T prefab) where T : UnityEngine.Component
public RegistrationBuilder MapComponentInNewPrefab<T>(T prefab) where T : UnityEngine.Component
{
containerBuilder.RegisterComponentInNewPrefab(prefab, Lifetime.Singleton);
MapRoutesInfos.Add(MapRoutesInfo.Analyze(typeof(T)));
return containerBuilder.RegisterComponentInNewPrefab(prefab, Lifetime.Singleton);
}

public RoutingBuilder Sequential()
{
Filters.Add<SequentialOrdering>();
return this;
}

[Obsolete("Use Sequential instead.")]
public RoutingBuilder FirstInFirstOut()
{
Filters.Add<FirstInFirstOutOrdering>();
Expand Down Expand Up @@ -195,6 +204,9 @@ static void RegisterVitalRouterInterceptors(this IContainerBuilder builder, Rout
{
switch (routing.Ordering)
{
case CommandOrdering.Sequential:
routing.Filters.Add<SequentialOrdering>();
break;
case CommandOrdering.FirstInFirstOut:
routing.Filters.Add<FirstInFirstOutOrdering>();
break;
Expand Down

0 comments on commit a62480b

Please sign in to comment.