-
Notifications
You must be signed in to change notification settings - Fork 0
Description
Background
As of right now, there is only one way to render every single property's value on an ImmutableBase<TImmutable> inheriting class: the IStringFormatter initialized with the DefaultStringFormatter implementation. However, further down in our closed source code, there are ImmutableBase<TImmutable> implementations that store values which are sensitive - like reset tokens for emails. Those value objects that should not output their sensitive values if they are to be printed into loggers.
Therefore, I need to add the ability for an inheriting class to control which IStringFormatter is used for a given property. This can be done in a similar manner to #45.
Task
-
Create two new interfaces, as follows:
public interface IStringFormatterFactory { IStringFormatter Create(PropertyInfo property); } public interface IStringFormatterProvider { bool IsSupported(PropertyInfo property); }
-
Create one implementation,
DefaultStringFormatterProvider, that supports all types and does nothing but return the currentDefaultStringFormatterimplementation. -
Create an
AggregateStringFormatterProviderthat takes in a list ofIStringFormatterProviderimplementations and processes them in order. The first match is used to create anIStringFormatter. -
Use an
IStringFormatterFactoryin theImmutableBase<TImmutable>static constructor to hydrateIStringFormatterimplementations for each property instead of hard-coding all property values to useDefaultStringFormatteras it does today. It should have a public getter and setter such that others can change how properties are cached. Additionally, when it changes its value, that should cause all of the cachedIStringFormatterimplementations to be rebuilt using the newIStringFormatterFactory.
public static IStringFormatterFactory StringFormatterFactory {
get { return formatterFactory; }
set { formatterFactory = value; ClearFormattersCache(); }
}
static ImmutableBase() {
formatterFactory = new AggregateStringFormatterProvider(
new DefaultStringFormatterProvider()
);
// ... other initialization code.
}