Each applicationProgramYou need to perform initialization tasks at startup and cleanup when you exit. Such tasks are classified as bootstrapper, an open-source project on codeplex. For details, see http://bootstrapper.codeplex.com/to help us complete the next task.
1. When necessary, we can separate the implementation from the interface to implement dependency injection (the project reference is not required, but the DLL under the folder is required ). Then, we need to inject these implementations when the website application or other applications are started. Here, we need to mention that, because we separate the implementation from the interface, we can make the two components reference each other, for example, the implementation of Configuration Service can call the interface of information center to record logs, while the implementation of information center can call the interface of Configuration Service to store configurations.
2. Then, we need to initialize each component, for example, data initialization. This step must be completed after 1.
Of course, there can also be 3, 4, and 5, which are called bootstrappertask. When an application is started, as long as the Assembly contains bootstrappertask, bootstrapper will automatically find these tasks and call them in parallel by group by order. At the end of the application, bootstrapper will also call all dispose in sequence to clean up the tasks.
Use bootstrapper to initialize differentCodeIt is organized into different tasks (implementing the istartuptask Interface), and then these tasks are called through the fluent API of Bootstrap. bootstrapper, And the execution sequence of the tasks can be specified.
Loneliness is so beautiful: Discontinuing from application_start, making initialization code more elegant