Actually ModifiedProperties
is an implementation detail. Do any ILogFactory
need to produce that before and after format? I don't think so.
Anyway, I believe that ModifiedProperties
shouldn't be injected but they should be part of an interface like ICanTrackPropertyChanges
:
public interface ICanTrackPropertyChanges
{
IEnumerable<string> ModifiedPropertyNames { get; }
}
And ICanTrackPropertyChanges
should be implemented by your entities. Thus, UpdateLogFactory
can make the following assertion:
ICanTrackPropertyChanges trackable = entity as ICanTrackPropertyChanges;
// Design by contract wins!
Contract.Assert(trackable != null);
// And now access trackable.ModifiedProperties and produce the
// customized message for entity updates
This way, you don't need to provide ModifiedProperties
as an implementation detail of ILogFactory
, but you believe that entities can track property changes if they implement an interface.
You can enforce this using generic constraints:
public interface IUpdateLogFactory<TEntity> : ILogFactory
where TEntity : class, ICanTrackPropertyChanges
{
}
...and use this interface to implement loggeable entity updates.
In addition, you get an improvement: IUpdateLogFactory<TEntity>
implementations won't need to check if an entity has ModifiedProperty
because handled entities are guaranteed to has the whole IEnumerable<string>
of modified properties at compile time!