-
Notifications
You must be signed in to change notification settings - Fork 53
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Adds AddSingleton overload that accepts a factory
- Loading branch information
1 parent
df59529
commit b8ae8ce
Showing
8 changed files
with
199 additions
and
24 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
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,31 @@ | ||
using System; | ||
using Reflex.Core; | ||
|
||
namespace Reflex.Resolvers | ||
{ | ||
internal sealed class SingletonFactoryResolver : Resolver | ||
{ | ||
private readonly Func<Container, object> _factory; | ||
private object _instance; | ||
|
||
public SingletonFactoryResolver(Func<Container, object> factory, Type concrete) | ||
{ | ||
RegisterCallSite(); | ||
_factory = factory; | ||
Concrete = concrete; | ||
} | ||
|
||
public override object Resolve(Container container) | ||
{ | ||
IncrementResolutions(); | ||
|
||
if (_instance == null) | ||
{ | ||
_instance = _factory.Invoke(container); | ||
Disposables.TryAdd(_instance); | ||
} | ||
|
||
return _instance; | ||
} | ||
} | ||
} |
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