Skip to content

Commit 3f36520

Browse files
committed
+ fix scopes in di
1 parent a9da0ae commit 3f36520

File tree

5 files changed

+10
-14
lines changed

5 files changed

+10
-14
lines changed

Deployf.Botf/BotfProgram.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ public static void StartBot(
2424

2525
var botOptions = builder.Configuration.GetSection("bot").Get<BotfOptions>();
2626
builder.Services.AddBotf(botOptions);
27+
builder.Services.AddHttpClient();
2728

2829
onConfigure?.Invoke(builder.Services, builder.Configuration);
2930

Deployf.Botf/IBotUserService.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,6 @@ public BotUserService()
2424
{
2525
return await _userService.GetUserIdWithRoles(tgUserId);
2626
}
27-
return (null, null); ;
27+
return (null, null);
2828
}
2929
}

Deployf.Botf/StartupExtensions.cs

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -70,15 +70,17 @@ public static IServiceCollection AddBotf(this IServiceCollection services, BotfO
7070

7171
foreach (var type in controllerTypes)
7272
{
73-
services.AddTransient(type);
73+
services.AddScoped(type);
7474
}
7575

7676
services.AddSingleton(routes);
7777
services.AddSingleton(states);
7878
services.AddSingleton(handlers);
7979
services.AddSingleton<PagingService>();
80+
8081
services.AddSingleton<IKeyValueStorage, InMemoryKeyValueStorage>();
8182
services.AddSingleton<ChainStorage>();
83+
8284
services.AddScoped<BotControllersMiddleware>();
8385
services.AddScoped<BotControllersChainMiddleware>();
8486
services.AddScoped<BotControllersFSMMiddleware>();
@@ -88,11 +90,14 @@ public static IServiceCollection AddBotf(this IServiceCollection services, BotfO
8890
services.AddScoped<BotControllersUnknownMiddleware>();
8991
services.AddScoped<BotControllersBeforeAllMiddleware>();
9092
services.AddScoped<BotControllersInvoker>();
93+
9194
services.AddScoped<IBotContextAccessor, BotContextAccessor>();
92-
services.AddSingleton<BotUserService>();
95+
96+
services.AddScoped<BotUserService>();
97+
9398
services.AddTransient<BotfBot>();
9499
services.AddSingleton(options);
95-
services.AddTransient<HttpClient>();
100+
96101
services.AddTransient(ctx => ctx.GetRequiredService<BotfBot>().Client);
97102
services.AddTransient<MessageSender>();
98103

Examples/Deployf.Botf.PingExample/Program.cs

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,4 @@ public async Task Unknown()
1010
Reply();
1111
await Send(Context.GetSafeTextPayload()!);
1212
}
13-
}
14-
15-
record State1;
16-
17-
class State1Controller : BotControllerState<State1>
18-
{
1913
}

Examples/Deployf.Botf.ReminderBot/Program.cs

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,6 @@
33
using Hangfire.Storage.SQLite;
44
using SQLite;
55

6-
BackgroundJobServer? hangfireServer = null;
7-
86
BotfProgram.StartBot(args, onConfigure: (svc, cfg) =>
97
{
108
var db = new SQLiteConnection("db.sqlite");
@@ -30,8 +28,6 @@
3028
app.UseHangfireDashboard();
3129
});
3230

33-
hangfireServer!.Dispose();
34-
3531
class HangfireActivator : JobActivator
3632
{
3733
readonly IServiceProvider _serviceProvider;

0 commit comments

Comments
 (0)