Skip to content

Commit

Permalink
feat: Chain To with creator
Browse files Browse the repository at this point in the history
  • Loading branch information
labbbirder committed Oct 16, 2023
1 parent 67035a1 commit c26c922
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 1 deletion.
7 changes: 7 additions & 0 deletions Documentation/usage-decorator.md.meta

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

7 changes: 7 additions & 0 deletions Documentation/usage-di.md.meta

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

7 changes: 7 additions & 0 deletions Documentation/usage-proxy.md.meta

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

15 changes: 14 additions & 1 deletion Runtime/ClassicalUsages/ServiceContainer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ public static class ServiceContainer
//: IServiceContainer
{
static ServiceScopeMode DefaultScopeMode => Single;
static Dictionary<Type, object> singletons = new();
internal static Dictionary<Type, object> singletons = new();
internal static Dictionary<(Type desiredType, Type declaringType), Info> lutInfos = new();
public static void ClearInstances()
{
Expand Down Expand Up @@ -250,6 +250,19 @@ public void To<TDest>(params object[] arguments) where TDest : TSource
ServiceContainer.Get(desiredType, declaringType);
}
}

public void To<TDest>(Func<TDest> creator) where TDest : TSource
{
var typePair = (desiredType, declaringType);
Debug.Log($"to {scopeMode} {typeof(TDest)}");
ServiceContainer.lutInfos[typePair] = new()
{
resultType = typeof(TDest),
scopeMode = scopeMode,
// constructorArguments = arguments,
};
ServiceContainer.singletons[typeof(TDest)] = creator();
}
}

struct Info
Expand Down

0 comments on commit c26c922

Please sign in to comment.