| | | 1 | | using Microsoft.EntityFrameworkCore.Infrastructure; |
| | | 2 | | using ZhEaIsNsAaBn.Infrastructure.Core; |
| | | 3 | | |
| | | 4 | | // ReSharper disable once CheckNamespace |
| | | 5 | | namespace Microsoft.EntityFrameworkCore; |
| | | 6 | | |
| | | 7 | | /// <summary> |
| | | 8 | | /// Reads the provider handlers registered for one <see cref="DbContext"/> through an <c>IDbContextOptionsExtension</c> |
| | | 9 | | /// <c>UseSqlServerInfrastructure()</c>). They live in the context's internal service provider, so each context can use |
| | | 10 | | /// provider; they are never resolved from the app's DI container. |
| | | 11 | | /// </summary> |
| | | 12 | | public static class InfrastructureServiceExtensions |
| | | 13 | | { |
| | | 14 | | /// <summary>The context's error classifier.</summary> |
| | | 15 | | /// <param name="dbContext">The context.</param> |
| | | 16 | | /// <returns>The classifier, or <see langword="null"/> when no provider registered one.</returns> |
| | | 17 | | /// <exception cref="ArgumentNullException"><paramref name="dbContext"/> is <see langword="null"/>.</exception> |
| | 588 | 18 | | public static IDbErrorClassifier? GetDbErrorClassifier( this DbContext dbContext ) => Find<IDbErrorClassifier>( dbCo |
| | | 19 | | |
| | | 20 | | /// <summary>The context's stored-procedure executor.</summary> |
| | | 21 | | /// <param name="dbContext">The context.</param> |
| | | 22 | | /// <returns>The executor, or <see langword="null"/> when no provider registered one.</returns> |
| | | 23 | | /// <exception cref="ArgumentNullException"><paramref name="dbContext"/> is <see langword="null"/>.</exception> |
| | 56 | 24 | | public static IStoredProcedureExecutor? GetStoredProcedureExecutor( this DbContext dbContext ) => Find<IStoredProced |
| | | 25 | | |
| | | 26 | | /// <summary>The context's model defaults.</summary> |
| | | 27 | | /// <param name="dbContext">The context.</param> |
| | | 28 | | /// <returns>The defaults, or <see langword="null"/> when no provider registered them.</returns> |
| | | 29 | | /// <exception cref="ArgumentNullException"><paramref name="dbContext"/> is <see langword="null"/>.</exception> |
| | 60 | 30 | | public static IModelDefaultsProvider? GetModelDefaultsProvider( this DbContext dbContext ) => Find<IModelDefaultsPro |
| | | 31 | | |
| | | 32 | | |
| | | 33 | | /// <summary>The executor, or a clear <see cref="InvalidOperationException"/>.</summary> |
| | | 34 | | internal static IStoredProcedureExecutor RequireStoredProcedureExecutor( this DbContext dbContext ) |
| | 40 | 35 | | => dbContext.GetStoredProcedureExecutor() |
| | 40 | 36 | | ?? throw new InvalidOperationException( $"No stored-procedure executor is registered for {dbContext.GetType() |
| | 40 | 37 | | + "e.g. options.UseSqlServer( connectionString ).UseSqlServerInfrastr |
| | | 38 | | |
| | | 39 | | private static T? Find< T >( DbContext dbContext ) |
| | | 40 | | where T : class |
| | | 41 | | { |
| | 704 | 42 | | ArgumentNullException.ThrowIfNull( dbContext ); |
| | | 43 | | |
| | 704 | 44 | | return dbContext.GetInfrastructure().GetService<T>(); |
| | | 45 | | } |
| | | 46 | | } |