Recommendations for using DI in a library using types in attributes

I am working on a library that simplifies application setup. In fact, library users either decorate their configuration classes with attributes or initialize parameters declaratively in the code. One or more sources could be specified from which one could read / write configuration properties (Accessors) or inherit the default value from the class. For example, the following:

[ConfigurationNamespace(DefaultAccessors = new Type[] { typeof(AppSettingsAccessor) })]
public class ClientConfiguration : Configuration<IClientConfiguration>
{
    [ConfigurationItem(Accessors = new Type[] { 
        typeof((RegistryAccessor)) 
     })]
    public bool BypassCertificateVerification { get; set; }
}

will be equivalent

var config = new Configuration<IClientConfiguration>();
config.SetDefaultAccessors(new[] { typeof(AppSettingsAccessor) });
config.SetPropertyAccessors(
    property: x => x.BypassCertificateVerification,
    accessors: new[] { typeof(RegistryAccessor) }
);

(AppSettings, ,.ini .. ..). , . , IoC . [] , - .

(, -, Activator.CreateInstance), - / ? , / -, . , MVC SignalR . 100% ? , factory , .

, , ( Type IConfigurationAccessor factory ).

+5
1

DSL , API . API Configuration<T> , . DSL . - :

var config = new Configuration<IClientConfiguration>();
config.DefaultAccessors.Add(new AppSettingsAccessor());
config.PropertyAccessorsFor(x => x.BypassCertificateVerification)
    .Add(new RegistryAccessor());

:

[AppSettingsConfiguration]
public class ClientConfiguration : Configuration<IClientConfiguration>
{
    [RegistryConfiguration]
    public bool BypassCertificateVerification { get; set; }
}

.

Serialization : , . , node Accessor.

, Accessors IAccessor, Factory:

public interface IAccessorFactory
{
    IAccessor CreateAccessor(ConfigurationAttribute configurationAttribute);
}

, , , , Product Trader, PLoPD4, , t , Factory - , - IAccessor.

+5

All Articles