Use IOptionsSnapshot in DefaultConnectionStringResolver to detect changes in appsettings file.

pull/81/head
Halil İbrahim Kalkan 9 years ago
parent 9a5707d167
commit 8ead16f389

@ -1,5 +1,6 @@
using System;
using Microsoft.Extensions.DependencyInjection;
using Volo.Abp;
namespace AbpDesk.ConsoleDemo
{
@ -13,20 +14,12 @@ namespace AbpDesk.ConsoleDemo
{
application.Initialize(scope.ServiceProvider);
application
.ServiceProvider
.GetRequiredService<TicketLister>()
.List();
RunDemo(application);
application
.ServiceProvider
.GetRequiredService<UserLister>()
.List();
Console.WriteLine("Press ENTER to run again...");
Console.ReadLine();
application
.ServiceProvider
.GetRequiredService<BlogPostLister>()
.List();
RunDemo(application);
Console.WriteLine();
Console.WriteLine("Press ENTER to exit...");
@ -35,5 +28,23 @@ namespace AbpDesk.ConsoleDemo
application.Shutdown();
}
}
private static void RunDemo(AbpApplication application)
{
application
.ServiceProvider
.GetRequiredService<TicketLister>()
.List();
application
.ServiceProvider
.GetRequiredService<UserLister>()
.List();
application
.ServiceProvider
.GetRequiredService<BlogPostLister>()
.List();
}
}
}

@ -15,7 +15,7 @@ namespace Microsoft.Extensions.DependencyInjection
.AddLogging();
services.TryAddTransient<TDbContext>();
services.TryAddSingleton(DbContextOptionsFactory.Create<TDbContext>);
services.TryAddTransient(DbContextOptionsFactory.Create<TDbContext>);
var options = new AbpDbContextRegistrationOptions();
optionsBuilder?.Invoke(options);

@ -14,7 +14,7 @@ namespace Volo.Abp.Data.MultiTenancy
private readonly ITenantConnectionStringStore _tenantConnectionStringStore;
public MultiTenantConnectionStringResolver(
IOptions<DbConnectionOptions> options,
IOptionsSnapshot<DbConnectionOptions> options,
IMultiTenancyManager multiTenancyManager,
ITenantConnectionStringStore tenantConnectionStringStore)
: base(options)

@ -7,9 +7,9 @@ namespace Volo.Abp.Data
{
public class DefaultConnectionStringResolver : IConnectionStringResolver, ITransientDependency
{
private readonly DbConnectionOptions _options; //TODO: Use IOptionsSnapshot?
private readonly DbConnectionOptions _options;
public DefaultConnectionStringResolver(IOptions<DbConnectionOptions> options)
public DefaultConnectionStringResolver(IOptionsSnapshot<DbConnectionOptions> options)
{
_options = options.Value;
}

Loading…
Cancel
Save