Browse Source

add dbcontext type to options.

master
yangxiaodong 7 years ago
parent
commit
3ec25195e7
5 changed files with 13 additions and 9 deletions
  1. +2
    -1
      src/DotNetCore.CAP.EntityFrameworkCore/CAP.BuilderExtensions.cs
  2. +3
    -2
      src/DotNetCore.CAP.EntityFrameworkCore/CapDbContext.cs
  3. +1
    -1
      src/DotNetCore.CAP.EntityFrameworkCore/CapPublisherExtensions.cs
  4. +5
    -5
      src/DotNetCore.CAP.EntityFrameworkCore/EFStorageConnection.cs
  5. +2
    -0
      src/DotNetCore.CAP.EntityFrameworkCore/SqlServerOptions.cs

+ 2
- 1
src/DotNetCore.CAP.EntityFrameworkCore/CAP.BuilderExtensions.cs View File

@@ -28,6 +28,7 @@ namespace Microsoft.Extensions.DependencyInjection
builder.Services.Configure(actionOptions);
var sqlServerOptions = new SqlServerOptions();
sqlServerOptions.DbContextType = typeof(TContext);
actionOptions(sqlServerOptions);
builder.Services.AddSingleton(sqlServerOptions);

@@ -44,6 +45,6 @@ namespace Microsoft.Extensions.DependencyInjection
return builder;
}

}
}

+ 3
- 2
src/DotNetCore.CAP.EntityFrameworkCore/CapDbContext.cs View File

@@ -28,8 +28,7 @@ namespace DotNetCore.CAP.EntityFrameworkCore
/// <summary>
/// Gets or sets the <see cref="CapSentMessage"/> of Messages.
/// </summary>
public DbSet<CapSentMessage> CapSentMessages { get; set; }
public DbSet<CapSentMessage> CapSentMessages { get; set; }

public DbSet<CapQueue> CapQueue { get; set; }

@@ -48,6 +47,7 @@ namespace DotNetCore.CAP.EntityFrameworkCore
/// </param>
protected override void OnModelCreating(ModelBuilder modelBuilder)
{
//_sqlServerOptions = new SqlServerOptions();
modelBuilder.HasDefaultSchema(_sqlServerOptions.Schema);

modelBuilder.Entity<CapSentMessage>(b =>
@@ -67,6 +67,7 @@ namespace DotNetCore.CAP.EntityFrameworkCore

protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
{
// optionsBuilder.UseSqlServer("Server=192.168.2.206;Initial Catalog=Test;User Id=cmswuliu;Password=h7xY81agBn*Veiu3;MultipleActiveResultSets=True");
}
}
}

+ 1
- 1
src/DotNetCore.CAP.EntityFrameworkCore/CapPublisherExtensions.cs View File

@@ -32,7 +32,7 @@ namespace DotNetCore.CAP

}

public static async Task Publish(this ICapPublisher publisher, string topic, string content, IDbConnection connection,IDbTransaction transaction)
public static async Task Publish(this ICapPublisher publisher, string topic, string content, IDbConnection connection, IDbTransaction transaction)
{
var message = new CapSentMessage
{


+ 5
- 5
src/DotNetCore.CAP.EntityFrameworkCore/EFStorageConnection.cs View File

@@ -108,14 +108,14 @@ WHERE StateName = '{StatusName.Enqueued}'";

private async Task<IFetchedMessage> FetchNextMessageCoreAsync(string sql, object args = null)
{
FetchedMessage fetchedJob = null;
FetchedMessage fetchedMessage = null;
var connection = _context.GetDbConnection();
var transaction = _context.Database.CurrentTransaction;
transaction = transaction ?? await _context.Database.BeginTransactionAsync(IsolationLevel.ReadCommitted);

try
{
fetchedJob =
fetchedMessage =
(await connection.QueryAsync<FetchedMessage>(sql, args, transaction.GetDbTransaction()))
.FirstOrDefault();
}
@@ -125,7 +125,7 @@ WHERE StateName = '{StatusName.Enqueued}'";
throw;
}

if (fetchedJob == null)
if (fetchedMessage == null)
{
transaction.Rollback();
transaction.Dispose();
@@ -133,8 +133,8 @@ WHERE StateName = '{StatusName.Enqueued}'";
}

return new EFFetchedMessage(
fetchedJob.MessageId,
fetchedJob.Type,
fetchedMessage.MessageId,
fetchedMessage.Type,
connection,
transaction);
}


+ 2
- 0
src/DotNetCore.CAP.EntityFrameworkCore/SqlServerOptions.cs View File

@@ -31,5 +31,7 @@ namespace DotNetCore.CAP.EntityFrameworkCore
/// Default is <see cref="DefaultMigrationsHistoryTableName"/>.
/// </summary>
public string MigrationsHistoryTableName { get; set; } = DefaultMigrationsHistoryTableName;

public Type DbContextType { get; set; }
}
}

Loading…
Cancel
Save