Skip to content

Commit

Permalink
docs: add XML documentation for every member
Browse files Browse the repository at this point in the history
  • Loading branch information
skarllot committed Oct 7, 2023
1 parent b311d80 commit 554fdae
Show file tree
Hide file tree
Showing 22 changed files with 185 additions and 4 deletions.
1 change: 0 additions & 1 deletion src/Directory.Build.props
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
<PropertyGroup>
<PackageReadmeFile>README.md</PackageReadmeFile>
<GenerateDocumentationFile>true</GenerateDocumentationFile>
<NoWarn>$(NoWarn);CS1591</NoWarn>
</PropertyGroup>

<ItemGroup>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@

namespace Raiqub.Expressions.EntityFrameworkCore;

/// <summary>
/// Extension methods for setting up Raiqub Expressions related services in an <see cref="IServiceCollection"/>.
/// </summary>
public static class ExpressionsServiceCollectionExtensions
{
/// <summary>Gets a builder for registering sessions and session factories using Entity Framework Core.</summary>
Expand Down
2 changes: 2 additions & 0 deletions src/Expressions.EntityFrameworkCore/Options/EntityOptions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ namespace Raiqub.Expressions.EntityFrameworkCore.Options;
/// </summary>
public sealed class EntityOptions
{
/// <summary>Initializes a new instance of the <see cref="EntityOptions"/> class.</summary>
/// <param name="entityType">The type of the entity to configure.</param>
public EntityOptions(Type entityType) => EntityType = entityType;

/// <summary>The type of the entity that this options configures.</summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@ public sealed class EntityOptionsConfiguration
{
private readonly Action<EntityOptions> _configure;

/// <summary>Initializes a new instance of the <see cref="EntityOptionsConfiguration"/> class.</summary>
/// <param name="entityType">The type of the entity to configure.</param>
/// <param name="configure">The action used to configure the options.</param>
public EntityOptionsConfiguration(Type entityType, Action<EntityOptions> configure)
{
EntityType = entityType;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,13 @@
/// <summary>An selector that retrieves an <see cref="EntityOptions"/> based on a specified entity type.</summary>
public sealed class EntityOptionsSelector
{
/// <summary>Provides a value to use with sessions that do not have configuration.</summary>
public static readonly EntityOptionsSelector Empty = new(Array.Empty<EntityOptionsConfiguration>());

private readonly Dictionary<Type, EntityOptions> _dictionary;

/// <summary>Initializes a new instance of the <see cref="EntityOptionsSelector"/> class.</summary>
/// <param name="configurations">The collection of configurations.</param>
public EntityOptionsSelector(IEnumerable<EntityOptionsConfiguration> configurations)
{
_dictionary = configurations
Expand Down
17 changes: 17 additions & 0 deletions src/Expressions.EntityFrameworkCore/Queries/EfDbQuery.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,18 @@

namespace Raiqub.Expressions.EntityFrameworkCore.Queries;

/// <summary>
/// Entity Framework-based implementation of a query that can be executed to retrieve instances of type <typeparamref name="TResult"/>.
/// </summary>
/// <typeparam name="TResult">The type of the result returned.</typeparam>
public class EfDbQuery<TResult> : IDbQuery<TResult>
{
private readonly ILogger _logger;
private readonly IQueryable<TResult> _dataSource;

/// <summary>Initializes a new instance of the <see cref="EfDbQuery{TResult}"/> class.</summary>
/// <param name="logger">The <see cref="ILogger"/> to log to.</param>
/// <param name="dataSource">The data source to query from.</param>
public EfDbQuery(
ILogger logger,
IQueryable<TResult> dataSource)
Expand All @@ -19,6 +26,7 @@ public EfDbQuery(
_dataSource = dataSource;
}

/// <inheritdoc />
public async Task<bool> AnyAsync(CancellationToken cancellationToken = default)
{
try
Expand All @@ -35,6 +43,7 @@ public async Task<bool> AnyAsync(CancellationToken cancellationToken = default)
}
}

/// <inheritdoc />
public async Task<int> CountAsync(CancellationToken cancellationToken = default)
{
try
Expand All @@ -51,6 +60,7 @@ public async Task<int> CountAsync(CancellationToken cancellationToken = default)
}
}

/// <inheritdoc />
public async Task<TResult> FirstAsync(CancellationToken cancellationToken = default)
{
try
Expand All @@ -68,6 +78,7 @@ and not InvalidOperationException
}
}

/// <inheritdoc />
public async Task<TResult?> FirstOrDefaultAsync(CancellationToken cancellationToken = default)
{
try
Expand All @@ -84,6 +95,7 @@ and not InvalidOperationException
}
}

/// <inheritdoc />
public async Task<long> LongCountAsync(CancellationToken cancellationToken = default)
{
try
Expand All @@ -100,6 +112,7 @@ public async Task<long> LongCountAsync(CancellationToken cancellationToken = def
}
}

/// <inheritdoc />
public async Task<TPage> ToPagedListAsync<TPage>(
int pageNumber,
int pageSize,
Expand Down Expand Up @@ -138,6 +151,7 @@ public async Task<TPage> ToPagedListAsync<TPage>(
return pagedResultFactory(new PageInfo(pageNumber, pageSize, totalCount), items);
}

/// <inheritdoc />
public async Task<IReadOnlyList<TResult>> ToListAsync(CancellationToken cancellationToken = default)
{
List<TResult> items;
Expand All @@ -158,6 +172,7 @@ public async Task<IReadOnlyList<TResult>> ToListAsync(CancellationToken cancella
return items;
}

/// <inheritdoc />
public async Task<TResult> SingleAsync(CancellationToken cancellationToken = default)
{
try
Expand All @@ -175,6 +190,7 @@ and not InvalidOperationException
}
}

/// <inheritdoc />
public async Task<TResult?> SingleOrDefaultAsync(CancellationToken cancellationToken = default)
{
try
Expand All @@ -192,6 +208,7 @@ and not InvalidOperationException
}
}

/// <inheritdoc />
public async IAsyncEnumerable<TResult> ToAsyncEnumerable(
[EnumeratorCancellation] CancellationToken cancellationToken = default)
{
Expand Down
7 changes: 7 additions & 0 deletions src/Expressions.EntityFrameworkCore/Queries/EfQuerySource.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,19 @@

namespace Raiqub.Expressions.EntityFrameworkCore.Queries;

/// <summary>Entity framework-based implementation of provider of data sources.</summary>
public class EfQuerySource : IQuerySource
{
private readonly DbContext _dbContext;
private readonly ISqlProviderSelector _sqlProviderSelector;
private readonly EntityOptionsSelector _entityOptionsSelector;
private readonly ChangeTracking _tracking;

/// <summary>Initializes a new instance of the <see cref="EfQuerySource"/> class.</summary>
/// <param name="dbContext">The <see cref="Microsoft.EntityFrameworkCore.DbContext"/> to read/write.</param>
/// <param name="sqlProviderSelector">A selector to retrieve custom SQL for querying entities.</param>
/// <param name="entityOptionsSelector">A selector to retrieve options for handling entities.</param>
/// <param name="tracking">The change tracking mode of the session.</param>
public EfQuerySource(
DbContext dbContext,
ISqlProviderSelector sqlProviderSelector,
Expand All @@ -24,6 +30,7 @@ public EfQuerySource(
_tracking = tracking;
}

/// <inheritdoc />
public IQueryable<TEntity> GetSet<TEntity>() where TEntity : class
{
EntityOptions? options = _entityOptionsSelector.GetOptions<TEntity>();
Expand Down
26 changes: 26 additions & 0 deletions src/Expressions.EntityFrameworkCore/Sessions/EfDbSession.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,18 @@

namespace Raiqub.Expressions.EntityFrameworkCore.Sessions;

/// <summary>Entity Framework-based implementation of a database session for querying and saving instances.</summary>
public class EfDbSession : IDbSession
{
private readonly ILogger<EfDbSession> _logger;
private readonly EfQuerySource _querySource;

/// <summary>Initializes a new instance of the <see cref="EfDbSession"/> class.</summary>
/// <param name="logger">The <see cref="ILogger"/> to log to.</param>
/// <param name="dbContext">The <see cref="Microsoft.EntityFrameworkCore.DbContext"/> to read/write.</param>
/// <param name="sqlProviderSelector">A selector to retrieve custom SQL for querying entities.</param>
/// <param name="optionsSelector">A selector to retrieve options for handling entities.</param>
/// <param name="tracking">The change tracking mode of the session.</param>
public EfDbSession(
ILogger<EfDbSession> logger,
DbContext dbContext,
Expand All @@ -25,21 +32,28 @@ public EfDbSession(
_querySource = new EfQuerySource(dbContext, sqlProviderSelector, optionsSelector, tracking);
}

/// <summary>Gets the Entity Framework session of this database session.</summary>
public DbContext DbContext { get; }

/// <inheritdoc />
public ChangeTracking Tracking { get; }

/// <inheritdoc />
public async ValueTask<IDbSessionTransaction> BeginTransactionAsync(CancellationToken cancellationToken = default)
{
var transaction = await DbContext.Database.BeginTransactionAsync(cancellationToken).ConfigureAwait(false);
return new EfDbSessionTransaction(transaction);
}

/// <inheritdoc />
public void Add<TEntity>(TEntity entity)
where TEntity : class => DbContext.Add(entity);

/// <inheritdoc />
public void AddRange<TEntity>(IEnumerable<TEntity> entities)
where TEntity : class => DbContext.AddRange(entities);

/// <inheritdoc />
public async ValueTask AddAsync<TEntity>(TEntity entity, CancellationToken cancellationToken = default)
where TEntity : class
{
Expand All @@ -48,6 +62,7 @@ await DbContext
.ConfigureAwait(false);
}

/// <inheritdoc />
public async ValueTask AddRangeAsync<TEntity>(
IEnumerable<TEntity> entities,
CancellationToken cancellationToken = default)
Expand All @@ -58,45 +73,56 @@ await DbContext
.ConfigureAwait(false);
}

/// <inheritdoc />
public IDbQuery<TResult> Query<TResult>(IQueryStrategy<TResult> queryStrategy)
{
return new EfDbQuery<TResult>(
_logger,
queryStrategy.Execute(_querySource));
}

/// <inheritdoc />
public void Remove<TEntity>(TEntity entity) where TEntity : class => DbContext.Remove(entity);

/// <inheritdoc />
public void RemoveRange<TEntity>(IEnumerable<TEntity> entities)
where TEntity : class => DbContext.RemoveRange(entities);

/// <inheritdoc />
public Task SaveChangesAsync(CancellationToken cancellationToken = default) =>
DbContext.SaveChangesAsync(true, cancellationToken);

/// <inheritdoc />
public void Update<TEntity>(TEntity entity)
where TEntity : class => DbContext.Update(entity);

/// <inheritdoc />
public void UpdateRange<TEntity>(IEnumerable<TEntity> entities)
where TEntity : class => DbContext.UpdateRange(entities);

/// <inheritdoc />
public async ValueTask DisposeAsync()
{
await DisposeAsyncCore().ConfigureAwait(false);
Dispose(disposing: false);
GC.SuppressFinalize(this);
}

/// <inheritdoc />
public void Dispose()
{
Dispose(disposing: true);
GC.SuppressFinalize(this);
}

/// <summary>DisposeAsync method for implementations to write.</summary>
protected virtual async ValueTask DisposeAsyncCore()
{
await DbContext.DisposeAsync();
}

/// <summary>Dispose method for implementations to write.</summary>
/// <param name="disposing"><see langword="true" /> to release both managed and unmanaged resources; <see langword="false" /> to release only unmanaged resources.</param>
protected virtual void Dispose(bool disposing)
{
if (disposing)
Expand Down
11 changes: 11 additions & 0 deletions src/Expressions.EntityFrameworkCore/Sessions/EfDbSessionFactory.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

namespace Raiqub.Expressions.EntityFrameworkCore.Sessions;

/// <summary>Entity Framework-based implementation of a factory for creating database sessions for data access.</summary>
public class EfDbSessionFactory<TContext>
: IDbSessionFactory<TContext>, IDbQuerySessionFactory<TContext>, IDbSessionFactory, IDbQuerySessionFactory
where TContext : DbContext
Expand All @@ -16,6 +17,11 @@ public class EfDbSessionFactory<TContext>
private readonly ISqlProviderSelector _sqlProviderSelector;
private readonly EntityOptionsSelector _optionsSelector;

/// <summary>Initializes a new instance of the <see cref="EfDbSessionFactory{TContext}"/> class.</summary>
/// <param name="loggerFactory">The factory used to create loggers.</param>
/// <param name="contextFactory">The factory for creating <see cref="DbContext"/> instances.</param>
/// <param name="sqlProviderSelector">A selector to retrieve custom SQL for querying entities.</param>
/// <param name="optionsSelector">A selector to retrieve options for handling entities.</param>
public EfDbSessionFactory(
ILoggerFactory loggerFactory,
IDbContextFactory<TContext> contextFactory,
Expand All @@ -28,8 +34,13 @@ public EfDbSessionFactory(
_optionsSelector = optionsSelector;
}

/// <summary>Creates a new database session.</summary>
/// <param name="tracking">The change tracking mode of the new session.</param>
/// <returns>A new database session.</returns>
public EfDbSession<TContext> Create(ChangeTracking? tracking = null) => CreateWithContext(tracking);

/// <summary>Creates a new database query session.</summary>
/// <returns>A new database query session.</returns>
public EfDbSession<TContext> CreateForQuery() => Create(ChangeTracking.Disable);

IDbSession IDbSessionFactory.Create(ChangeTracking? tracking) => CreateWithoutContext(tracking);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,19 +3,25 @@

namespace Raiqub.Expressions.EntityFrameworkCore.Sessions;

/// <summary>Entity Framework-based implementation of started database transaction.</summary>
public sealed class EfDbSessionTransaction : IDbSessionTransaction
{
private readonly IDbContextTransaction _contextTransaction;

/// <summary>Initializes a new instance of the <see cref="EfDbSessionTransaction"/> class.</summary>
/// <param name="contextTransaction">The Entity Framework transaction to wrap.</param>
public EfDbSessionTransaction(IDbContextTransaction contextTransaction) =>
_contextTransaction = contextTransaction;

/// <inheritdoc />
public Task CommitAsync(CancellationToken cancellationToken = default) =>
_contextTransaction.CommitAsync(cancellationToken);

/// <inheritdoc />
public ValueTask DisposeAsync() =>
_contextTransaction.DisposeAsync();

/// <inheritdoc />
public void Dispose() =>
_contextTransaction.Dispose();
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,17 @@

namespace Raiqub.Expressions.EntityFrameworkCore.Sessions;

/// <summary>Entity Framework-based implementation of a database session for querying and saving instances.</summary>
/// <typeparam name="TContext">The type of the bounded context.</typeparam>
public class EfDbSession<TContext> : EfDbSession, IDbSession<TContext>
where TContext : DbContext
{
/// <summary>Initializes a new instance of the <see cref="EfDbSession{TContext}"/> class.</summary>
/// <param name="logger">The <see cref="ILogger"/> to log to.</param>
/// <param name="context">The <see cref="Microsoft.EntityFrameworkCore.DbContext"/> to read/write.</param>
/// <param name="sqlProviderSelector">A selector to retrieve custom SQL for querying entities.</param>
/// <param name="optionsSelector">A selector to retrieve options for handling entities.</param>
/// <param name="tracking">The change tracking mode of the session.</param>
public EfDbSession(
ILogger<EfDbSession<TContext>> logger,
TContext context,
Expand All @@ -21,5 +29,6 @@ public EfDbSession(
Context = context;
}

/// <inheritdoc />
public TContext Context { get; }
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,12 @@

namespace Raiqub.Expressions.Marten;

/// <summary>
/// Extension methods for setting up Raiqub Expressions related services in an <see cref="IServiceCollection"/>.
/// </summary>
public static class ExpressionsServiceCollectionExtensions
{
/// <summary>Gets a builder for registering sessions and session factories using Entity Framework Core.</summary>
/// <summary>Gets a builder for registering sessions and session factories using Marten.</summary>
/// <param name="services">The <see cref="IServiceCollection"/> to add services to.</param>
/// <param name="tracking">The change tracking mode of injected sessions.</param>
/// <returns>The <see cref="ExpressionsSessionBuilder"/> so that add context calls can be chained in it.</returns>
Expand Down
Loading

0 comments on commit 554fdae

Please sign in to comment.