Skip to content

Configuration

Fabio Gouw edited this page Apr 18, 2025 · 4 revisions

The Configuration Model

NHilo follows the flexible configuration model of .NET Core / .NET 5 since version 2.0.0. The configuration schema is composed by two sections.

{
  "ConnectionStrings": {
      "myDB": {
         "ConnectionString": "Server=myServerAddress;Database=myDataBase;User Id=myUsername;Password=myPassword;",
             "ProviderName": "Microsoft.Data.SqlClient"
      }
  },
  "NHilo": {
     "ConnectionStringId": "",
     "ProviderName": "",
     "CreateHiLoStructureIfNotExists": true,
     "DefaultMaxLo": 100,
     "TableName": "",
     "NextHiColumnName": "",
     "EntityColumnName": "",
     "StorageType": "",
     "ObjectPrefix": "",
     "EntityNameValidationTimeout": 1000
     "Entities": [
         { "name": "", "maxLo" : 10 }   
     ]
  }
}

The first one is the ConnectionStrings. It follows the same structure of the connection strings section used by EF, for example, so no critical changes are needed to make it work. This is importante if you project already uses a database and you'd like to reuse that again to store the NHilo's data. NHilo will consider the last connection string in the section, if you have more than one. The only thing that it requires is the ProviderName attribute, so NHilo can tell which database provider it needs to load.

If your configuration file has the same schema shown in the previous code snippet, NHilo can get the provider name from that. However, there are some projects that uses the ConnectionStrings as follows:

{
  "ConnectionStrings": {
      "myDB": "Data Source=|DataDirectory|\\Database1.sdf;Persist Security Info=False;"
  }
}

In this case, the provider name must be supplied in the NHilo's configuration schema. You only need to configure the attribute you want to change, otherwise they're all optional.

  • ConnectionStringId is an optional attribute that defines which connection string will be used to locate the database where NHilo will store the values of the "hi" number for the entities. If this information is not provided, then the last connection string will be used.
  • ProviderName is an optional attribute unless you don't define the provider name in the ConnectionStrings section.
  • CreateHiLoStructureIfNotExists is an optional attribute that tell NHilo to try to create the table used for storing the "hi" numbers. Default is true.
  • DefaultMaxLo is the default value for the "lo" part of the key. Its also optional with a default value of 100.
  • TableName allows you to specify the name of the table that will hold the "hi" value for each entity. It's important if you project needs to follow some corporate database naming rules. The default value is "NHILO"
  • NextHiColumnName allows you to specify the name of the hi value column that will hold the "hi" value for each entity. It's important if you project needs to follow some corporate database naming rules. The default value is "NEXT_HI"
  • EntityColumnName allows you to specify the name of the entity name column that will hold the "hi" value for each entity. It's important if you project needs to follow some corporate database naming rules. The default value is "ENTITY"
  • StorageType for SQL Server, defines if the hi values will be stored in the database using tables (the default option) or sequences.
  • ObjectPrefix for SQL Server and sequences, defines the prefix of the names of the sequences. The default value is "SQ_HiLo_".
  • EntityNameValidationTimeout (optional) allows the override of the default timeout for entity name validation (10ms). Set it for a higher value, like 100ms, if you're receiving EntityNameValidationTimedOut errors.
  • Entities groups the configuration of each entity. It's optional too and it's useful if you need a specific maxlo value for a given entity.
    • Name is the name of the entity which this configuration will be applied.
    • MaxLo is the max "lo" number for the given entity.

Available Data Providers

  • Microsoft.Data.SqlClient for SQL Server
  • MySqlConnector for MySQL
  • System.Data.OracleClient for Oracle
  • NHilo.InMemory for testing-only purpose, it uses the memory of the application processes and it's not persisted in disk

Clone this wiki locally