{"record":{"id":"458dbb00d88dc2fe","repo":"abpframework/abp","slug":"services-have-already-been-configured-if-you-call","errorCode":null,"errorMessage":"Services have already been configured! If you call ConfigureServicesAsync method, you must have set AbpApplicationCreationOptions.SkipConfigureServices to true before.","messagePattern":"Services have already been configured! If you call ConfigureServicesAsync method, you must have set AbpApplicationCreationOptions\\.SkipConfigureServices to true before\\.","errorType":"exception","errorClass":"AbpInitializationException","httpStatus":null,"severity":"critical","filePath":"framework/src/Volo.Abp.Core/Volo/Abp/AbpApplicationBase.cs","lineNumber":306,"sourceCode":"\n        foreach (var module in Modules)\n        {\n            if (module.Instance is AbpModule abpModule)\n            {\n                abpModule.ServiceConfigurationContext = null!;\n            }\n        }\n\n        _configuredServices = true;\n\n        TryToSetEnvironment(Services);\n    }\n\n    private void CheckMultipleConfigureServices()\n    {\n        if (_configuredServices)\n        {\n            throw new AbpInitializationException(\"Services have already been configured! If you call ConfigureServicesAsync method, you must have set AbpApplicationCreationOptions.SkipConfigureServices to true before.\");\n        }\n    }\n\n    //TODO: We can extract a new class for this\n    public virtual void ConfigureServices()\n    {\n        CheckMultipleConfigureServices();\n\n        var context = new ServiceConfigurationContext(Services);\n        Services.AddSingleton(context);\n\n        foreach (var module in Modules)\n        {\n            if (module.Instance is AbpModule abpModule)\n            {\n                abpModule.ServiceConfigurationContext = context;\n            }\n        }","sourceCodeStart":288,"sourceCodeEnd":324,"githubUrl":"https://github.com/abpframework/abp/blob/7ed43b1931b9df46a50c0c59148a18645641d0df/framework/src/Volo.Abp.Core/Volo/Abp/AbpApplicationBase.cs#L288-L324","documentation":"ConfigureServices() / ConfigureServicesAsync() may run only once per AbpApplication; the private _configuredServices flag enforces this. When you create the app WITHOUT setting AbpApplicationCreationOptions.SkipConfigureServices, the constructor itself calls ConfigureServices() before returning. Calling ConfigureServicesAsync() afterward trips the guard. The flag exists so hosts that need to defer configuration (external DI, tests) can opt out and configure manually.","triggerScenarios":"Creating the app via a factory that auto-configures, then calling ConfigureServicesAsync() again; or calling ConfigureServices()/ConfigureServicesAsync() twice in code.","commonSituations":"Migrating from sync to async init and forgetting to remove the old call; a test harness that re-inits the same app; mixing AddApplicationAsync (auto-configures) with a manual ConfigureServicesAsync.","solutions":["Pass options => options.SkipConfigureServices = true when creating the app, then call ConfigureServicesAsync() yourself exactly once.","Or remove the duplicate call and let the framework configure once (the default path does it in the constructor).","If using AbpApplicationFactory.CreateAsync, it auto-configures - do not call ConfigureServicesAsync again on the result."],"exampleFix":"// before\nawait AbpApplicationFactory.CreateAsync<MyModule>(services);\nawait application.ConfigureServicesAsync(); // throws\n\n// after\nawait AbpApplicationFactory.CreateAsync<MyModule>(services,\n    options => options.SkipConfigureServices = true);\nawait application.ConfigureServicesAsync();","handlingStrategy":"validation","validationCode":"// When you need to configure manually, opt out of auto-config at creation:\nvar app = await AbpApplicationFactory.CreateAsync<MyModule>(services,\n    options => options.SkipConfigureServices = true);\nawait app.ConfigureServicesAsync(); // now safe, exactly once","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Pick one initialization path (auto or manual) and do not mix them.","Document in Program.cs / the test fixture that SkipConfigureServices is intentional when set.","Grep for ConfigureServicesAsync/ConfigureServices calls to ensure exactly one per app instance."],"tags":["module-system","initialization","configuration","double-init"],"backgroundTag":null,"analyzedSha":"7ed43b1931b9df46a50c0c59148a18645641d0df","analyzedAt":"2026-08-13T16:26:11.351Z","schemaVersion":2},"datasetVersion":"2026-08-13T19:17:28.613Z"}