Skip to content

Commit

Permalink
fixing scoped services for DryIoc
Browse files Browse the repository at this point in the history
  • Loading branch information
dansiegel committed Nov 28, 2019
1 parent 00239cc commit 32bf5de
Showing 1 changed file with 9 additions and 5 deletions.
14 changes: 9 additions & 5 deletions src/Prism.DryIoc.Extensions/PrismContainerExtension.cs
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ private PrismContainerExtension(IContainer container)
Instance.UseInstance<IServiceProvider>(this);
}

private IDisposable _currentScope;
private IResolverContext _currentScope;

public IContainer Instance { get; private set; }

Expand Down Expand Up @@ -222,20 +222,23 @@ public IContainerRegistry RegisterScopedFromDelegate(Type serviceType, Func<ISer
void IScopeProvider.CreateScope()
{
_currentScope?.Dispose();
_currentScope = null;
GC.Collect();
_currentScope = Instance.OpenScope();
}

public object Resolve(Type type) =>
Resolve(type, new (Type, object)[0]);
Resolve(type, Array.Empty<(Type, object)>());

public object Resolve(Type type, string name) =>
Resolve(type, name, new (Type, object)[0]);
Resolve(type, name, Array.Empty<(Type, object)>());

public object Resolve(Type type, params (Type Type, object Instance)[] parameters)
{
try
{
return Instance.Resolve(type, args: parameters.Select(p => p.Instance).ToArray());
var container = _currentScope ?? Instance;
return container.Resolve(type, args: parameters.Select(p => p.Instance).ToArray());
}
catch (Exception ex)
{
Expand All @@ -247,7 +250,8 @@ public object Resolve(Type type, string name, params (Type Type, object Instance
{
try
{
return Instance.Resolve(type, name, args: parameters.Select(p => p.Instance).ToArray());
var container = _currentScope ?? Instance;
return container.Resolve(type, name, args: parameters.Select(p => p.Instance).ToArray());
}
catch(Exception ex)
{
Expand Down

0 comments on commit 32bf5de

Please sign in to comment.