-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
minor fix to defaults in the properties container, Added test demonst…
…rating IgnoreDefaultValues
- Loading branch information
1 parent
ee5550b
commit 88a1cde
Showing
4 changed files
with
149 additions
and
13 deletions.
There are no files selected for viewing
100 changes: 100 additions & 0 deletions
100
src/Conventions.Abstractions/ConventionHostBuilderExtensions.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,100 @@ | ||
namespace Rocket.Surgery.Conventions | ||
{ | ||
/// <summary> | ||
/// Base convention extensions | ||
/// </summary> | ||
public static class ConventionHostBuilderExtensions | ||
{ | ||
/// <summary> | ||
/// Get a value by type from the context | ||
/// </summary> | ||
/// <typeparam name="T"></typeparam> | ||
/// <param name="context">The context</param> | ||
/// <returns>T.</returns> | ||
public static T Get<T>(this IConventionHostBuilder context) | ||
{ | ||
return (T)context.ServiceProperties[typeof(T)]; | ||
} | ||
|
||
/// <summary> | ||
/// Get a value by key from the context | ||
/// </summary> | ||
/// <typeparam name="T"></typeparam> | ||
/// <param name="context">The context</param> | ||
/// <param name="key">The key where the value is saved</param> | ||
/// <returns>T.</returns> | ||
public static T Get<T>(this IConventionHostBuilder context, string key) | ||
{ | ||
return (T)context.ServiceProperties[key]; | ||
} | ||
|
||
/// <summary> | ||
/// Get a value by type from the context | ||
/// </summary> | ||
/// <typeparam name="T">The type of the value</typeparam> | ||
/// <param name="context">The context</param> | ||
/// <param name="value">The value to save</param> | ||
public static void Set<T>(this IConventionHostBuilder context, T value) | ||
{ | ||
context.ServiceProperties[typeof(T)] = value; | ||
} | ||
|
||
/// <summary> | ||
/// Get a value by type from the context | ||
/// </summary> | ||
/// <typeparam name="T">The type of the value</typeparam> | ||
/// <param name="context">The context</param> | ||
/// <param name="key">The key where the value is saved</param> | ||
/// <param name="value">The value to save</param> | ||
public static void Set<T>(this IConventionHostBuilder context, string key, T value) | ||
{ | ||
context.ServiceProperties[key] = value; | ||
} | ||
|
||
/// <summary> | ||
/// Get a value by type from the context | ||
/// </summary> | ||
/// <typeparam name="T"></typeparam> | ||
/// <param name="serviceProviderDictionary">The context</param> | ||
/// <returns>T.</returns> | ||
public static T Get<T>(this IServiceProviderDictionary serviceProviderDictionary) | ||
{ | ||
return (T)serviceProviderDictionary[typeof(T)]; | ||
} | ||
|
||
/// <summary> | ||
/// Get a value by key from the context | ||
/// </summary> | ||
/// <typeparam name="T"></typeparam> | ||
/// <param name="serviceProviderDictionary">The context</param> | ||
/// <param name="key">The key where the value is saved</param> | ||
/// <returns>T.</returns> | ||
public static T Get<T>(this IServiceProviderDictionary serviceProviderDictionary, string key) | ||
{ | ||
return (T)serviceProviderDictionary[key]; | ||
} | ||
|
||
/// <summary> | ||
/// Get a value by type from the context | ||
/// </summary> | ||
/// <typeparam name="T">The type of the value</typeparam> | ||
/// <param name="serviceProviderDictionary">The context</param> | ||
/// <param name="value">The value to save</param> | ||
public static void Set<T>(this IServiceProviderDictionary serviceProviderDictionary, T value) | ||
{ | ||
serviceProviderDictionary[typeof(T)] = value; | ||
} | ||
|
||
/// <summary> | ||
/// Get a value by type from the context | ||
/// </summary> | ||
/// <typeparam name="T">The type of the value</typeparam> | ||
/// <param name="serviceProviderDictionary">The context</param> | ||
/// <param name="key">The key where the value is saved</param> | ||
/// <param name="value">The value to save</param> | ||
public static void Set<T>(this IServiceProviderDictionary serviceProviderDictionary, string key, T value) | ||
{ | ||
serviceProviderDictionary[key] = value; | ||
} | ||
} | ||
} |
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