forked from hadashiA/VContainer
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'develop' into SupportForValueTypesFuncRegistration
- Loading branch information
Showing
13 changed files
with
278 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
26 changes: 26 additions & 0 deletions
26
VContainer/Assets/VContainer/Runtime/Internal/FuncRegistrationBuilderWithCallback.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
using System; | ||
|
||
namespace VContainer.Internal | ||
{ | ||
sealed class FuncRegistrationBuilderWithCallback : RegistrationBuilder | ||
{ | ||
readonly Func<IObjectResolver, object> implementationProvider; | ||
readonly Action<object, IObjectResolver> callback; | ||
|
||
public FuncRegistrationBuilderWithCallback( | ||
Func<IObjectResolver, object> implementationProvider, | ||
Type implementationType, | ||
Lifetime lifetime, | ||
Action<object, IObjectResolver> callback) : base(implementationType, lifetime) | ||
{ | ||
this.implementationProvider = implementationProvider; | ||
this.callback = callback; | ||
} | ||
|
||
public override Registration Build() | ||
{ | ||
var spawner = new InstanceProviderCallbackDecorator(new FuncInstanceProvider(implementationProvider), callback); | ||
return new Registration(ImplementationType, Lifetime, InterfaceTypes, spawner); | ||
} | ||
} | ||
} |
11 changes: 11 additions & 0 deletions
11
VContainer/Assets/VContainer/Runtime/Internal/FuncRegistrationBuilderWithCallback.cs.meta
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
23 changes: 23 additions & 0 deletions
23
...Assets/VContainer/Runtime/Internal/InstanceProviders/InstanceProviderCallbackDecorator.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
using System; | ||
|
||
namespace VContainer.Internal | ||
{ | ||
sealed class InstanceProviderCallbackDecorator : IInstanceProvider | ||
{ | ||
readonly Action<object, IObjectResolver> callback; | ||
readonly IInstanceProvider instanceProvider; | ||
|
||
public InstanceProviderCallbackDecorator(IInstanceProvider instanceProvider, Action<object, IObjectResolver> callback) | ||
{ | ||
this.instanceProvider = instanceProvider; | ||
this.callback = callback; | ||
} | ||
|
||
public object SpawnInstance(IObjectResolver resolver) | ||
{ | ||
var instance = instanceProvider.SpawnInstance(resolver); | ||
callback(instance, resolver); | ||
return instance; | ||
} | ||
} | ||
} |
Oops, something went wrong.