コード例 #1
0
    // AddRedisOperationLogChangeTracking

    public static DbContextBuilder <TDbContext> AddRedisOperationLogChangeTracking <TDbContext>(
        this DbContextBuilder <TDbContext> dbContextBuilder,
        Action <IServiceProvider, RedisOperationLogChangeTrackingOptions <TDbContext> >?configureOptions = null)
        where TDbContext : DbContext
    {
        var services = dbContextBuilder.Services;

        services.TryAddSingleton(c => {
            var options = new RedisOperationLogChangeTrackingOptions <TDbContext>();
            configureOptions?.Invoke(c, options);
            return(options);
        });

        // RedisOperationLogChangeTracker<TDbContext>
        services.TryAddSingleton <RedisOperationLogChangeTracker <TDbContext> >();
        services.AddHostedService(c =>
                                  c.GetRequiredService <RedisOperationLogChangeTracker <TDbContext> >());
        services.TryAddSingleton <IDbOperationLogChangeTracker <TDbContext> >(c =>
                                                                              c.GetRequiredService <RedisOperationLogChangeTracker <TDbContext> >());

        // RedisOperationLogChangeNotifier<TDbContext>
        services.TryAddEnumerable(
            ServiceDescriptor.Singleton <
                IOperationCompletionListener,
                RedisOperationLogChangeNotifier <TDbContext> >());
        return(dbContextBuilder);
    }
コード例 #2
0
 public RedisOperationLogChangeNotifier(
     RedisOperationLogChangeTrackingOptions <TDbContext> options,
     AgentInfo agentInfo,
     IServiceProvider services)
     : base(services)
 {
     Options   = options;
     AgentInfo = agentInfo;
     RedisDb   = Services.GetService <RedisDb <TDbContext> >() ?? Services.GetRequiredService <RedisDb>();
     RedisPub  = RedisDb.GetPub(options.PubSubKey);
     Log.LogInformation("Using pub/sub key = '{Key}'", RedisPub.FullKey);
 }
コード例 #3
0
 public RedisOperationLogChangeTracker(
     RedisOperationLogChangeTrackingOptions <TDbContext> options,
     AgentInfo agentInfo,
     IServiceProvider services)
     : base(services)
 {
     Options   = options;
     AgentInfo = agentInfo;
     RedisDb   = Services.GetService <RedisDb <TDbContext> >() ?? Services.GetRequiredService <RedisDb>();
     RedisSub  = RedisDb.GetChannelSub(options.PubSubKey);
     Log.LogInformation("Using pub/sub key = '{Key}'", RedisSub.FullKey);
     // ReSharper disable once VirtualMemberCallInConstructor
     ReplaceNextEventTask();
 }