Project Setup
Table Of Contents
Connection String
Before you can interact with the database from your application using The Sharp Factory Framework you will need to register the connection string.
Because multiple models are supported you will need to register one connection string per model in your project.
Registering The Connection String
We recommend registering the connection string(s) early in the execution pipeline.
For example in your Program.cs class; more specifically in your Main method. Or in the configured entry point for your application.
The Database.RegisterModelConnectionString takes 2 parameters:
-
int modelId: The code generator assigns a unique model id to each model added to the model container. This can easily be accessed from the RepoLookup.ModelId static class.
-
string connectionString: This is the connection string that your application will use during runtime to access the database.
The Repository Container
The RepositoryContainer class is the starting point for all data access and manipulation. This class does not keep any state. This means it can be used as a singleton and we recommend you do so. However you are not constraint to do so if you wish otherwise.
The code sample below register a connection string for a model called AppDb.