custom configuration - AlienEngineer/VirtualObjects GitHub Wiki

Custom Configuration

There's an atempt to keep the solution as configurable as possible. Each instance of Session is associated with a SessionConfiguration instance.

A first layer of configuration is the way POCO classes are mapped into Tables.

public virtual void ConfigureMappingBuilder(ITranslationConfigurationBuilder builder)
{
    //
    // Table Name Mapping
    builder.EntityName(e => e.Name);
    builder.EntityName<TableAttribute>(e => e.TableName);

    //
    // Column Name Mapping
    builder.ColumnName(e => e.Name);
    builder.ColumnName<ColumnAttribute>(e => e.FieldName);

    //
    // Column Key Mapping
    builder.ColumnKey<KeyAttribute>();
    // ...
}

This SessionConfiguration can be derived and _ConfigureMappingBuilder _can be overrided and developers can create they're own POCO mapping binders.

// Example:
var session = new Session(new SessionConfiguration {
    Logger = Console.Out,
    SaveGeneratedCode = true,
    ConnectionProvider = new FirstConnectionDbConnectionProvider()
});

ConnectionProvider

The connection provider defines the rules about how the connection is created. By default it is used NamedDbConnectionProvider. This provider uses a connection string named after the current computer name.

This provider also can receive a custom name. (e.g. new NamedDbConnectionProvider("DataSource")).

Logger

Use this option to debug purposes. Don't log on Release mode. Performance hit.

SaveGeneratedCode

Use this option when an error happens mapping an entity. It will save the code that maps entities into a file. Don't use this option on Release mode. Performance hit.