Skip to content

Commit

Permalink
feature and tests RegisterAnd (#725)
Browse files Browse the repository at this point in the history
* tests and feature of RegisterAnd

RegisterAnd allows serial registration or chaining.

* Add tests, change Enumerable.Empty to Array.Empty

Co-authored-by: David Vreony <dpvreony@users.noreply.github.com>
  • Loading branch information
ChrisPulman and dpvreony authored Jul 20, 2021
1 parent b9e7f80 commit 7d25d07
Show file tree
Hide file tree
Showing 13 changed files with 729 additions and 7 deletions.
14 changes: 14 additions & 0 deletions src/Splat.Common.Test/IViewModelOne.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
// Copyright (c) 2021 .NET Foundation and Contributors. All rights reserved.
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for full license information.

namespace Splat.Common.Test
{
/// <summary>
/// Interface for ViewModelOne.
/// </summary>
public interface IViewModelOne
{
}
}
8 changes: 7 additions & 1 deletion src/Splat.Common.Test/ViewModelOne.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,13 @@ namespace Splat.Common.Test
/// <summary>
/// View Model One.
/// </summary>
public class ViewModelOne
public class ViewModelOne : IViewModelOne
{
/// <summary>
/// Initializes a new instance of the <see cref="ViewModelOne"/> class.
/// </summary>
public ViewModelOne()
{
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ public virtual IEnumerable<object> GetServices(Type serviceType, string? contrac
services = dic?
.GetFactories(contract)
.Select(f => f())
?? Enumerable.Empty<object>();
?? Array.Empty<object>();
}

return services;
Expand Down Expand Up @@ -370,7 +370,7 @@ public bool TryRemoveContract(string contract) =>
public IEnumerable<Func<object>> GetFactories(string contract) =>
_dictionary.TryGetValue(contract, out var collection)
? collection ?? Enumerable.Empty<Func<object>>()
: Enumerable.Empty<Func<object>>();
: Array.Empty<Func<object>>();

public void AddFactory(string contract, Func<object> factory) =>
_dictionary.AddOrUpdate(contract, _ => new List<Func<object>> { factory }, (_, list) =>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ public IEnumerable<object> GetServices(Type serviceType, string? contract = null
return new[] { registration.GetInstance() };
}

return Enumerable.Empty<object>();
return Array.Empty<object>();
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,8 @@ namespace Splat
public static System.Collections.Generic.IEnumerable<T> GetServices<T>(this Splat.IReadonlyDependencyResolver resolver, string? contract = null) { }
public static void Register<T>(this Splat.IMutableDependencyResolver resolver, System.Func<T> factory, string? contract = null)
where T : notnull { }
public static void Register<TAs, T>(this Splat.IMutableDependencyResolver resolver, string? contract = null)
where T : new() { }
public static void RegisterConstant(this Splat.IMutableDependencyResolver resolver, object value, System.Type serviceType, string? contract = null) { }
public static void RegisterConstant<T>(this Splat.IMutableDependencyResolver resolver, T value, string? contract = null)
where T : notnull { }
Expand Down Expand Up @@ -568,6 +570,23 @@ namespace Splat
public static System.Tuple<System.Drawing.RectangleF, System.Drawing.RectangleF> DivideWithPadding(this System.Drawing.RectangleF value, float sliceAmount, float padding, Splat.RectEdge fromEdge) { }
public static System.Drawing.RectangleF InvertWithin(this System.Drawing.RectangleF value, System.Drawing.RectangleF containingRect) { }
}
public static class ResolverMixins
{
public static Splat.IMutableDependencyResolver RegisterAnd<T>(this Splat.IMutableDependencyResolver resolver, string? contract = null)
where T : new() { }
public static Splat.IMutableDependencyResolver RegisterAnd<T>(this Splat.IMutableDependencyResolver resolver, System.Func<T> factory, string? contract = null) { }
public static Splat.IMutableDependencyResolver RegisterAnd<TAs, T>(this Splat.IMutableDependencyResolver resolver, string? contract = null)
where T : new() { }
public static Splat.IMutableDependencyResolver RegisterAnd<TAs, T>(this Splat.IMutableDependencyResolver resolver, System.Func<T> factory, string? contract = null) { }
public static Splat.IMutableDependencyResolver RegisterConstantAnd(this Splat.IMutableDependencyResolver resolver, object value, System.Type serviceType, string? contract = null) { }
public static Splat.IMutableDependencyResolver RegisterConstantAnd<T>(this Splat.IMutableDependencyResolver resolver, string? contract = null)
where T : new() { }
public static Splat.IMutableDependencyResolver RegisterConstantAnd<T>(this Splat.IMutableDependencyResolver resolver, T value, string? contract = null) { }
public static Splat.IMutableDependencyResolver RegisterLazySingletonAnd(this Splat.IMutableDependencyResolver resolver, System.Func<object> valueFactory, System.Type serviceType, string? contract = null) { }
public static Splat.IMutableDependencyResolver RegisterLazySingletonAnd<T>(this Splat.IMutableDependencyResolver resolver, string? contract = null)
where T : new() { }
public static Splat.IMutableDependencyResolver RegisterLazySingletonAnd<T>(this Splat.IMutableDependencyResolver resolver, System.Func<T> valueFactory, string? contract = null) { }
}
public static class ServiceLocationInitialization
{
public static void InitializeSplat(this Splat.IMutableDependencyResolver resolver) { }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,8 @@ namespace Splat
public static System.Collections.Generic.IEnumerable<T> GetServices<T>(this Splat.IReadonlyDependencyResolver resolver, string? contract = null) { }
public static void Register<T>(this Splat.IMutableDependencyResolver resolver, System.Func<T> factory, string? contract = null)
where T : notnull { }
public static void Register<TAs, T>(this Splat.IMutableDependencyResolver resolver, string? contract = null)
where T : new() { }
public static void RegisterConstant(this Splat.IMutableDependencyResolver resolver, object value, System.Type serviceType, string? contract = null) { }
public static void RegisterConstant<T>(this Splat.IMutableDependencyResolver resolver, T value, string? contract = null)
where T : notnull { }
Expand Down Expand Up @@ -568,6 +570,23 @@ namespace Splat
public static System.Tuple<System.Drawing.RectangleF, System.Drawing.RectangleF> DivideWithPadding(this System.Drawing.RectangleF value, float sliceAmount, float padding, Splat.RectEdge fromEdge) { }
public static System.Drawing.RectangleF InvertWithin(this System.Drawing.RectangleF value, System.Drawing.RectangleF containingRect) { }
}
public static class ResolverMixins
{
public static Splat.IMutableDependencyResolver RegisterAnd<T>(this Splat.IMutableDependencyResolver resolver, string? contract = null)
where T : new() { }
public static Splat.IMutableDependencyResolver RegisterAnd<T>(this Splat.IMutableDependencyResolver resolver, System.Func<T> factory, string? contract = null) { }
public static Splat.IMutableDependencyResolver RegisterAnd<TAs, T>(this Splat.IMutableDependencyResolver resolver, string? contract = null)
where T : new() { }
public static Splat.IMutableDependencyResolver RegisterAnd<TAs, T>(this Splat.IMutableDependencyResolver resolver, System.Func<T> factory, string? contract = null) { }
public static Splat.IMutableDependencyResolver RegisterConstantAnd(this Splat.IMutableDependencyResolver resolver, object value, System.Type serviceType, string? contract = null) { }
public static Splat.IMutableDependencyResolver RegisterConstantAnd<T>(this Splat.IMutableDependencyResolver resolver, string? contract = null)
where T : new() { }
public static Splat.IMutableDependencyResolver RegisterConstantAnd<T>(this Splat.IMutableDependencyResolver resolver, T value, string? contract = null) { }
public static Splat.IMutableDependencyResolver RegisterLazySingletonAnd(this Splat.IMutableDependencyResolver resolver, System.Func<object> valueFactory, System.Type serviceType, string? contract = null) { }
public static Splat.IMutableDependencyResolver RegisterLazySingletonAnd<T>(this Splat.IMutableDependencyResolver resolver, string? contract = null)
where T : new() { }
public static Splat.IMutableDependencyResolver RegisterLazySingletonAnd<T>(this Splat.IMutableDependencyResolver resolver, System.Func<T> valueFactory, string? contract = null) { }
}
public static class ServiceLocationInitialization
{
public static void InitializeSplat(this Splat.IMutableDependencyResolver resolver) { }
Expand Down
Loading

0 comments on commit 7d25d07

Please sign in to comment.