Question

Is this the right way to do a console application's data context?

AppTools
     .Init("App's daily operations", 
           false,
           new GlobalLogic(),
           () => new DataAccessState(cn => cn.Open()));

If not, then how to do it?

Was it helpful?

Solution

If you're talking about a server-side console app, you don't even need to call AppTools.Init. Here's the correct way:

  1. In your console project, create a class file called Program.cs.
  2. In the file, your class should look like this:

    partial class Program {
      static partial void initGlobalLogic( ref SystemLogic globalLogic ) {
        globalLogic = new YourGlobalLogicClass();
      }
    
      static partial void ewlMain( string[] args ) {
        DataAccessState.Current.PrimaryDatabaseConnection.ExecuteWithConnectionOpen( () => {
          // Your code goes here.
          // Skip the ExecuteWithConnectionOpen call if you don't need the database.
        }
      }
    }
    
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top