-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathEntityFrameworkRepositoryFactory.cs
More file actions
100 lines (92 loc) · 4.59 KB
/
EntityFrameworkRepositoryFactory.cs
File metadata and controls
100 lines (92 loc) · 4.59 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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
// =================================================================================================================================
// Copyright (c) RapidField LLC. Licensed under the MIT License. See LICENSE.txt in the project root for license information.
// =================================================================================================================================
using Microsoft.EntityFrameworkCore;
using Microsoft.Extensions.Configuration;
using RapidField.SolidInstruments.Core.ArgumentValidation;
using RapidField.SolidInstruments.ObjectComposition;
using System;
namespace RapidField.SolidInstruments.DataAccess.EntityFramework
{
/// <summary>
/// Encapsulates creation of new Entity Framework <see cref="IDataAccessRepository" /> instances that map to database entities.
/// </summary>
/// <remarks>
/// <see cref="EntityFrameworkRepositoryFactory{TContext}" /> is the default implementation of
/// <see cref="IEntityFrameworkRepositoryFactory{TContext}" />.
/// </remarks>
/// <typeparam name="TContext">
/// The type of the database session that is used by the produced repositories.
/// </typeparam>
public abstract class EntityFrameworkRepositoryFactory<TContext> : DataAccessRepositoryFactory, IEntityFrameworkRepositoryFactory<TContext>
where TContext : DbContext
{
/// <summary>
/// Initializes a new instance of the <see cref="EntityFrameworkRepositoryFactory{TContext}" /> class.
/// </summary>
/// <param name="context">
/// The database session that is used by the produced repositories.
/// </param>
/// <exception cref="ArgumentNullException">
/// <paramref name="context" /> is <see langword="null" />.
/// </exception>
protected EntityFrameworkRepositoryFactory(TContext context)
: base()
{
Context = context.RejectIf().IsNull(nameof(context));
}
/// <summary>
/// Initializes a new instance of the <see cref="EntityFrameworkRepositoryFactory{TContext}" /> class.
/// </summary>
/// <param name="context">
/// The database session that is used by the produced repositories.
/// </param>
/// <param name="applicationConfiguration">
/// Configuration information for the application.
/// </param>
/// <exception cref="ArgumentNullException">
/// <paramref name="context" /> is <see langword="null" /> -or- <paramref name="applicationConfiguration" /> is
/// <see langword="null" />.
/// </exception>
protected EntityFrameworkRepositoryFactory(TContext context, IConfiguration applicationConfiguration)
: base(applicationConfiguration)
{
Context = context.RejectIf().IsNull(nameof(context));
}
/// <summary>
/// Configures the current <see cref="EntityFrameworkRepositoryFactory{TContext}" />.
/// </summary>
/// <param name="configuration">
/// Configuration information for the current <see cref="EntityFrameworkRepositoryFactory{TContext}" />.
/// </param>
protected override void Configure(ObjectFactoryConfiguration<IDataAccessRepository> configuration) => Configure(configuration, Context);
/// <summary>
/// Configures the current <see cref="EntityFrameworkRepositoryFactory{TContext}" />.
/// </summary>
/// <param name="configuration">
/// Configuration information for the current <see cref="EntityFrameworkRepositoryFactory{TContext}" />.
/// </param>
/// <param name="context">
/// The database session that is used by the produced repositories.
/// </param>
protected abstract void Configure(ObjectFactoryConfiguration<IDataAccessRepository> configuration, TContext context);
/// <summary>
/// Releases all resources consumed by the current <see cref="EntityFrameworkRepositoryFactory{TContext}" />.
/// </summary>
/// <param name="disposing">
/// A value indicating whether or not managed resources should be released.
/// </param>
protected override void Dispose(Boolean disposing) => base.Dispose(disposing);
/// <summary>
/// Gets the database session that is used by the produced repositories.
/// </summary>
public TContext Context
{
get;
}
/// <summary>
/// Gets the type of the database session that is used by the produced repositories.
/// </summary>
public Type ContextType => typeof(TContext);
}
}