Repository navigation
Expand file tree
/
Copy pathCAP.OracleOptions.cs
More file actions
46 lines (39 loc) · 1.78 KB
/
Copy pathCAP.OracleOptions.cs
File metadata and controls
46 lines (39 loc) · 1.78 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
// Copyright (c) .NET Core Community. All rights reserved.
// Licensed under the MIT License. See License.txt in the project root for license information.
using System;
using DotNetCore.CAP.Internal;
using Microsoft.EntityFrameworkCore;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Options;
// ReSharper disable once CheckNamespace
namespace DotNetCore.CAP;
public class OracleOptions : EFOptions
{
/// <summary>
/// Gets or sets the database's connection string that will be used to store database entities.
/// </summary>
public string ConnectionString { get; set; } = default!;
}
internal class ConfigureOracleOptions : IConfigureOptions<OracleOptions>
{
private readonly IServiceScopeFactory _serviceScopeFactory;
public ConfigureOracleOptions(IServiceScopeFactory serviceScopeFactory)
{
_serviceScopeFactory = serviceScopeFactory;
}
public void Configure(OracleOptions options)
{
if (options.DbContextType != null)
{
if (Helper.IsUsingType<ICapPublisher>(options.DbContextType))
throw new InvalidOperationException(
"We detected that you are using ICapPublisher in DbContext, please change the configuration to use the storage extension directly to avoid circular references! eg: x.UseOracle()");
using var scope = _serviceScopeFactory.CreateScope();
var provider = scope.ServiceProvider;
using var dbContext = (DbContext)provider.GetRequiredService(options.DbContextType);
var connectionString = dbContext.Database.GetConnectionString();
if (string.IsNullOrEmpty(connectionString)) throw new ArgumentNullException(connectionString);
options.ConnectionString = connectionString;
}
}
}