Issue
I have main method:
Future<Null> main() async {
final securityService = new SecurityService(new BrowserClient());
await securityService.getObject();
bootstrapStatic<AppComponent>(
AppComponent,
<dynamic>[
provide<SecurityService>(SecurityService,
useFactory: () => securityService, deps: []),
provide<BrowserClient>(BrowserClient,
useFactory: () => new BrowserClient(), deps: []),
routerProvidersHash
],
ng.initReflector as Function);
}
I want to rewrite it to use bootstrapFactory
. How to do that? What should I rewrite in components with providers: const [MyService]
?
Solution
So, I wrote this:
// ignore: uri_has_not_been_generated
import 'package:budget/app_component.template.dart' as ng_app;
...
// ignore: uri_has_not_been_generated
import 'main.template.dart' as ng;
@GenerateInjector(const [
const ClassProvider<BrowserClient>(BrowserClient),
const FactoryProvider<SecurityService>(SecurityService, getSecurityService),
routerProvidersHash
])
final InjectorFactory appInjector = ng.appInjector$Injector;
SecurityService _securityService;
SecurityService getSecurityService() => _securityService;
Future<Null> main() async {
_securityService = new SecurityService(new BrowserClient());
await _securityService.getObject();
runApp<AppComponent>(
ng_app.AppComponentNgFactory as ComponentFactory<AppComponent>,
createInjector: appInjector);
}
Answered By – Cododoc
Answer Checked By – Pedro (FlutterFixes Volunteer)