dependency-injection

Flutter BlocListener executed only once even after event gets re-fired

若如初见. 提交于 2020-05-30 11:27:28
问题 I am implementing Reso Coder's clean architecture in flutter. I followed his guides in dividing the project to layers and using dependency injection. In one of the cases I want to have the following scenario: An administrator user logs in, sees data on their home screen, edits it and by pressing a button, saves the data to the local db (sqflite). Upon saving the data I want to show a Snackbar with some sort of text "Settings saved!" for example. Here's my code (parts): class AdministratorPage

.net core 3 dependency injecting services as parameters to 'configure'

岁酱吖の 提交于 2020-05-30 07:05:55
问题 I've just upgraded a .net core app from version 2.2 to 3. Inside the ConfigureServices method in startup.cs I need to resolve a service that is used by the authentication service. I was "building" all the services using "services.BuildServiceProvider()" but .net core 3 complains about the method creating additional copies of the services and suggesting me to dependency injecting services as parameters to 'configure'. I have no idea what the suggestion means and I'd like to understand it.

Inject bean at runtime reading properties file

限于喜欢 提交于 2020-05-29 14:07:27
问题 Suppose I have a class MailConsoleService and a class MailSMTPService , both implement the MailService interface. I have a class EmailJob which loads the users from a db and send an email through a MailService instance injected by Spring. How could I read a properties and determine at runtime which implementation of MailService to inject? The properties could change at any time the app is running, obviously. I've thought about to create a factory bean which returns the right instance from the

Scoped dependency use from NServiceBus Behavior

时光毁灭记忆、已成空白 提交于 2020-05-29 10:57:23
问题 I'm trying to use a Scoped dependency from a NServiceBus Behavior . From NServiceBus Behavior docs: Behaviors are only created once and the same instance is reused on every invocation of the pipeline. Consequently, every behavior dependency will also behave as a singleton, even if a different option was specified when registering it in dependency injection. Furthermore, the behavior, and all dependencies called during the invocation phase, need to be concurrency safe and possibly stateless.

Create scope factory in asp.net core

老子叫甜甜 提交于 2020-05-29 08:57:12
问题 I want to create scoped container in asp.net core and use it in 2 methods of my singleton method. I've tried create this in each method of sigleton. it works, but i think it is overhead. var scopeFactory = _serviceProvider.GetService<IServiceScopeFactory>(); var scope = scopeFactory.CreateScope(); var scopedContainer = scope.ServiceProvider; I write it in each method when i need it. I think it is logic mistake. Please, explain me how to do it correct? thank you 回答1: It is technically not

Angular (v5) service is getting constructed before APP_INITIALIZER promise resolves

。_饼干妹妹 提交于 2020-05-25 09:35:44
问题 I'm expecting Angular to wait until my loadConfig() function resolves before constructing other services, but it is not. app.module.ts export function initializeConfig(config: AppConfig){ return () => config.loadConfig(); } @NgModule({ declarations: [...] providers: [ AppConfig, { provide: APP_INITIALIZER, useFactory: initializeConfig, deps: [AppConfig], multi: true } ] }) export class AppModule { } app.config.ts @Injectable() export class AppConfig { config: any; constructor( private

Angular (v5) service is getting constructed before APP_INITIALIZER promise resolves

你。 提交于 2020-05-25 09:34:30
问题 I'm expecting Angular to wait until my loadConfig() function resolves before constructing other services, but it is not. app.module.ts export function initializeConfig(config: AppConfig){ return () => config.loadConfig(); } @NgModule({ declarations: [...] providers: [ AppConfig, { provide: APP_INITIALIZER, useFactory: initializeConfig, deps: [AppConfig], multi: true } ] }) export class AppModule { } app.config.ts @Injectable() export class AppConfig { config: any; constructor( private

Xamarin Forms - Pass Scope-Injected service from tabbedpageviewmodel to the viewmodels of the pages

我是研究僧i 提交于 2020-05-24 05:07:26
问题 In my xamarin forms application I have a tabbedpage with behind it a viewmodel. This viewmodel behind injects a service with dependency injection. That service is scoped. It should be scoped for the tabbedpageviewmodel. But the tabs should also make use of that scoped service. How can I achieve this? Should I pass the service to the tabbedpages-viewmodels? Singleton is not an option, because I work with notifications, the tabbedpageviewmodel can accur multiple times in the navigationstack,

Xamarin Forms - Pass Scope-Injected service from tabbedpageviewmodel to the viewmodels of the pages

做~自己de王妃 提交于 2020-05-24 05:07:00
问题 In my xamarin forms application I have a tabbedpage with behind it a viewmodel. This viewmodel behind injects a service with dependency injection. That service is scoped. It should be scoped for the tabbedpageviewmodel. But the tabs should also make use of that scoped service. How can I achieve this? Should I pass the service to the tabbedpages-viewmodels? Singleton is not an option, because I work with notifications, the tabbedpageviewmodel can accur multiple times in the navigationstack,

Autofac automate assembly scanning .net core 3.0 - Register according to Lifetime

放肆的年华 提交于 2020-05-23 21:11:28
问题 I realize this question is asked a lot. But I cannot figure out the solution to this problem. The thing i am trying to resolve is create three seperate interfaces (Singleton Scoped, InstancePerRequest). And register all the services under their implemented interface, without having to manually add them to DI container. Autofac Scanning Assemblies for certain class type Autofac register assembly types Autofac assembly scanning - .NET Core Before you say duplicate hear me out. I have provided a