Skip to content

Configuration

Max Stepanskiy edited this page Apr 19, 2021 · 37 revisions

Configuration must be initialized on application start-up. In case it is not, default configuration values will be assumed. Configuration values cannot be modified during run-time.

ObjectFactory.Configure()
     // specifies default connection name from connectionStrings configuration section
     .SetDefaultConnectionName("DbConnection")
          
     // specifies default change tracking mode used by unit-of-work implementation
     // ChangeTrackingMode.Automatic - detect changes automatically and produce merge script
     // ChangeTrackingMode.Manual - developer is responsible for committing his/her own changes;
     //                  unit-of-work implementation provides object level commit/rollback functionality
     //                  with implicit transaction
     // ChangeTrackingMode.Debug - same as Automatic except the merge script is not applied 
     //                            to the underlying storage, but sent to the output window
     .SetDefaultChangeTrackingMode(ChangeTrackingMode.Debug) 
     
     // specifies default materialization mode used by retrieve implementation
     // MaterializationMode.Partial - is a version tolerant materialization using dynamic proxy
     // Materialization.Exact - is a strict, not version tolerant materialization using dynamic method for mapping
     .SetDefaultMaterializationMode(MaterializationMode.Partial)

     // specifies default L1 cache implementation
     // CacheRepresentation.LazyList - cache as much data as necessary
     // CacheRepresentation.List - cache all data returned
     // CacheRepresentation.None - turn off L1 cache by default
     .SetDefaultCacheRepresentation(CacheRepresentation.LazyList)

     // specifies stored procedure naming convention
     // Default is OperationNamingConvention.Operation
     .SetDefaultOperationNamingConvention(OperationNamingConvention.PrefixTypeName_Operation)
          
     // specifies standard stored procedure prefix;
     // suppose a developer calls ObjectFactory.Retrieve for ICustomer 
     // with operation value "RetrieveByCountry"; given the naming convention from above,  
     // Retrieve will execute spDTO_Customer_RetrieveByCountry stored procedure
     .SetOperationPrefix("spDTO_")

     // specifies log provider implementation; log provider must implement ILogProvider interface;
     // when log provider is specified all internal traces and exceptions will be captured
     .SetLogProvider((ILogProvider)logProvider)

     // specifies default serialization mode used by Nemo binary serializer
     // SerializationMode.Compact               - serialized data does not include property names; 
     //                                           inclusion of the property names provides version tolerant 
     //                                           deserialization, thus this mode does not guarantee any
     //                                           version compatibility;
     //                                           by selecting this mode the resulting binary footprint 
     //                                           becomes smaller and property data is written in the 
     //                                           order it appears in the class/interface declaration; 
     //                                           properties marked with DoNotSerialize attribute are 
     //                                           skipped
     // SerializationMode.SerializeAll          - ignore DoNotSerialize attribute during serialization
     // SerializationMode.IncludePropertyNames  - include property names in serialized data; this mode 
     //                                           provides version tolerant deserialization given that 
     //                                           properties are added to the class/interface declaration
     .SetDefaultSerializationMode(SerializationMode.Compact)

     // specifies whether to enable delete statement generation vs. resorting to 
     // a naming convention based stored procedure; this works only with Delete() extension method;
     .SetGenerateDeleteSql(false)

     // specifies whether to enable insert statement generation vs. resorting to 
     // a naming convention based stored procedure; this works only with Insert() extension method;
     .SetGenerateInsertSql(false)

     // specifies whether to enable update statement generation vs. resorting to 
     // a naming convention based stored procedure; this works only with Update() extension method;
     .SetGenerateUpdateSql(false)

     // specifies audit log provider implementation; audit log provider must implement IAuditLogProvider interface;
     // when audit log provider is specified all CUD operations are audited and submitted to the provider;
     // by default audit log provider is not set
     .SetAuditLogProvider((IAuditLogProvider)auditLogProvider)
     
     // specifies execution context implementation; execution context must implement IExecutionContext interface;
     // by default execution context is set to DefaultExecutionContext provided by Nemo
     .SetExecutionContext((IExecutionContext)executionContext)

     // allows to enable/disable automatic type coercion; when enabled nullable and string properties are auto converted from DBNull
     // by default this option is disabled thus requiring explicit mapping for nullable and string properties
     .SetAutoTypeCoercion(true)

     // filters out unmatched parameters for queries and stored procedures (if stored procedures are supported); 
     // this option affects performance as Nemo has to either parse the command statement 
     // or query stored procedure meta-data prior to execution of the procedure;
     // stored procedure meta-data is cached per execution context as an optimization step;
     // by default this option is disabled
     .SetIgnoreInvalidParameters(true)

     // this option is valid only for applications that target .Net Core and provides an ability to inject IConfigurationRoot configuration
     // thus providing a way to retrieve connection strings information
     .SetSystemConfiguration((IConfigurationRoot)systemConfiguration);
Clone this wiki locally