Skip to content

Commit

Permalink
feature: add IDependencyResolver to the prism IContainerExtension ada…
Browse files Browse the repository at this point in the history
…pter
  • Loading branch information
glennawatson committed Nov 20, 2019
1 parent 4781037 commit 31cb5c9
Showing 1 changed file with 42 additions and 1 deletion.
43 changes: 42 additions & 1 deletion src/Splat.Prism/SplatContainerExtension.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
// See the LICENSE file in the project root for full license information.

using System;
using System.Collections.Generic;
using Prism.Ioc;

namespace Splat.Prism
Expand All @@ -12,7 +13,7 @@ namespace Splat.Prism
/// A container for the Prism application.
/// </summary>
[System.Diagnostics.CodeAnalysis.SuppressMessage("StyleCop.CSharp.NamingRules", "SA1316:Tuple element names should use correct casing", Justification = "Match Prism naming scheme.")]
public class SplatContainerExtension : IContainerExtension<IDependencyResolver>
public class SplatContainerExtension : IContainerExtension<IDependencyResolver>, IDependencyResolver
{
/// <summary>
/// Initializes a new instance of the <see cref="SplatContainerExtension"/> class.
Expand All @@ -27,12 +28,32 @@ public SplatContainerExtension()
/// </summary>
public IDependencyResolver Instance { get; } = new ModernDependencyResolver();

public void Dispose()
{
throw new NotImplementedException();
}

/// <inheritdoc/>
public void FinalizeExtension()
{
Locator.SetLocator(new ModernDependencyResolver());
}

public object GetService(Type serviceType, string contract = null)
{
return Instance.GetService(serviceType, contract);
}

public IEnumerable<object> GetServices(Type serviceType, string contract = null)
{
return Instance.GetServices(serviceType, contract);
}

public bool HasRegistration(Type serviceType, string contract = null)
{
return Instance.HasRegistration(serviceType, contract);
}

/// <inheritdoc/>
public bool IsRegistered(Type type)
{
Expand All @@ -59,6 +80,11 @@ public IContainerRegistry Register(Type from, Type to, string name)
return this;
}

public void Register(Func<object> factory, Type serviceType, string contract = null)
{
Instance.Register(factory, serviceType, contract);
}

/// <inheritdoc/>
public IContainerRegistry RegisterInstance(Type type, object instance)
{
Expand Down Expand Up @@ -110,5 +136,20 @@ public object Resolve(Type type, string name, params (Type Type, object Instance
{
throw new NotImplementedException();
}

public IDisposable ServiceRegistrationCallback(Type serviceType, string contract, Action<IDisposable> callback)
{
return Instance.ServiceRegistrationCallback(serviceType, contract, callback);
}

public void UnregisterAll(Type serviceType, string contract = null)
{
Instance.UnregisterAll(serviceType, contract);
}

public void UnregisterCurrent(Type serviceType, string contract = null)
{
Instance.UnregisterCurrent(serviceType, contract);
}
}
}

0 comments on commit 31cb5c9

Please sign in to comment.