|  | 
|  | 1 | +// Licensed to the .NET Foundation under one or more agreements. | 
|  | 2 | +// The .NET Foundation licenses this file to you under the MIT license. | 
|  | 3 | + | 
|  | 4 | +namespace Microsoft.EntityFrameworkCore.Infrastructure.Internal; | 
|  | 5 | + | 
|  | 6 | +/// <summary> | 
|  | 7 | +///     This is an internal API that supports the Entity Framework Core infrastructure and not subject to | 
|  | 8 | +///     the same compatibility standards as public APIs. It may be changed or removed without notice in | 
|  | 9 | +///     any release. You should only use it directly in your code with extreme caution and knowing that | 
|  | 10 | +///     doing so can result in application failures when updating to a new Entity Framework Core release. | 
|  | 11 | +/// </summary> | 
|  | 12 | +public class LazyLoaderFactory : ILazyLoaderFactory | 
|  | 13 | +{ | 
|  | 14 | +    private readonly ICurrentDbContext _currentContext; | 
|  | 15 | +    private readonly IDiagnosticsLogger<DbLoggerCategory.Infrastructure> _logger; | 
|  | 16 | +    private readonly List<ILazyLoader> _loaders = new(); | 
|  | 17 | + | 
|  | 18 | +    /// <summary> | 
|  | 19 | +    ///     This is an internal API that supports the Entity Framework Core infrastructure and not subject to | 
|  | 20 | +    ///     the same compatibility standards as public APIs. It may be changed or removed without notice in | 
|  | 21 | +    ///     any release. You should only use it directly in your code with extreme caution and knowing that | 
|  | 22 | +    ///     doing so can result in application failures when updating to a new Entity Framework Core release. | 
|  | 23 | +    /// </summary> | 
|  | 24 | +    public LazyLoaderFactory( | 
|  | 25 | +        ICurrentDbContext currentContext, | 
|  | 26 | +        IDiagnosticsLogger<DbLoggerCategory.Infrastructure> logger) | 
|  | 27 | +    { | 
|  | 28 | +        _currentContext = currentContext; | 
|  | 29 | +        _logger = logger; | 
|  | 30 | +    } | 
|  | 31 | + | 
|  | 32 | +    /// <summary> | 
|  | 33 | +    ///     This is an internal API that supports the Entity Framework Core infrastructure and not subject to | 
|  | 34 | +    ///     the same compatibility standards as public APIs. It may be changed or removed without notice in | 
|  | 35 | +    ///     any release. You should only use it directly in your code with extreme caution and knowing that | 
|  | 36 | +    ///     doing so can result in application failures when updating to a new Entity Framework Core release. | 
|  | 37 | +    /// </summary> | 
|  | 38 | +    public virtual ILazyLoader Create() | 
|  | 39 | +    { | 
|  | 40 | +        var loader = new LazyLoader(_currentContext, _logger); | 
|  | 41 | +        _loaders.Add(loader); | 
|  | 42 | +        return loader; | 
|  | 43 | +    } | 
|  | 44 | + | 
|  | 45 | +    /// <summary> | 
|  | 46 | +    ///     This is an internal API that supports the Entity Framework Core infrastructure and not subject to | 
|  | 47 | +    ///     the same compatibility standards as public APIs. It may be changed or removed without notice in | 
|  | 48 | +    ///     any release. You should only use it directly in your code with extreme caution and knowing that | 
|  | 49 | +    ///     doing so can result in application failures when updating to a new Entity Framework Core release. | 
|  | 50 | +    /// </summary> | 
|  | 51 | +    public void Dispose() | 
|  | 52 | +    { | 
|  | 53 | +        foreach (var loader in _loaders) | 
|  | 54 | +        { | 
|  | 55 | +            loader.Dispose(); | 
|  | 56 | +        } | 
|  | 57 | +        _loaders.Clear(); | 
|  | 58 | +    } | 
|  | 59 | + | 
|  | 60 | +    /// <summary> | 
|  | 61 | +    ///     This is an internal API that supports the Entity Framework Core infrastructure and not subject to | 
|  | 62 | +    ///     the same compatibility standards as public APIs. It may be changed or removed without notice in | 
|  | 63 | +    ///     any release. You should only use it directly in your code with extreme caution and knowing that | 
|  | 64 | +    ///     doing so can result in application failures when updating to a new Entity Framework Core release. | 
|  | 65 | +    /// </summary> | 
|  | 66 | +    public void ResetState() | 
|  | 67 | +        => Dispose(); | 
|  | 68 | + | 
|  | 69 | +    /// <summary> | 
|  | 70 | +    ///     This is an internal API that supports the Entity Framework Core infrastructure and not subject to | 
|  | 71 | +    ///     the same compatibility standards as public APIs. It may be changed or removed without notice in | 
|  | 72 | +    ///     any release. You should only use it directly in your code with extreme caution and knowing that | 
|  | 73 | +    ///     doing so can result in application failures when updating to a new Entity Framework Core release. | 
|  | 74 | +    /// </summary> | 
|  | 75 | +    public Task ResetStateAsync(CancellationToken cancellationToken = default) | 
|  | 76 | +    { | 
|  | 77 | +        Dispose(); | 
|  | 78 | + | 
|  | 79 | +        return Task.CompletedTask; | 
|  | 80 | +    } | 
|  | 81 | +} | 
0 commit comments