pokenae.Commons 1.0.18

There is a newer version of this package available.
See the version list below for details.
dotnet add package pokenae.Commons --version 1.0.18
                    
NuGet\Install-Package pokenae.Commons -Version 1.0.18
                    
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="pokenae.Commons" Version="1.0.18" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="pokenae.Commons" Version="1.0.18" />
                    
Directory.Packages.props
<PackageReference Include="pokenae.Commons" />
                    
Project file
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add pokenae.Commons --version 1.0.18
                    
#r "nuget: pokenae.Commons, 1.0.18"
                    
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
#addin nuget:?package=pokenae.Commons&version=1.0.18
                    
Install pokenae.Commons as a Cake Addin
#tool nuget:?package=pokenae.Commons&version=1.0.18
                    
Install pokenae.Commons as a Cake Tool

pokenae.Commons

概要

pokenae.Commonsプロジェクトは、共通のサービス、リポジトリ、エンティティ、DTO、マッピングプロファイル、データベースコンテキスト、フィルタなどを提供します。このプロジェクトは、他のプロジェクトで再利用可能な汎用的な機能を提供することを目的としています。

参照方法

以下の手順に従って、pokenae.Commonsプロジェクトを他のプロジェクトで参照し、利用することができます。

  1. プロジェクト参照の追加:

    • Visual Studio 2022で、pokenae.Commonsプロジェクトを右クリックし、「プロジェクトの依存関係」を選択します。
    • 依存関係を追加したいプロジェクトを選択し、「OK」をクリックします。
  2. NuGetパッケージの復元:

    • pokenae.Commonsプロジェクトで使用されているNuGetパッケージを復元します。ソリューションエクスプローラーでプロジェクトを右クリックし、「NuGet パッケージの復元」を選択します。
  3. 名前空間のインポート:

    • pokenae.Commonsプロジェクトのクラスやインターフェースを使用するために、必要な名前空間をインポートします。例えば、以下のようにインポートします。

    using pokenae.Commons.Filters; using pokenae.Commons.Data; using pokenae.Commons.DTOs; using pokenae.Commons.Entities; using pokenae.Commons.Mappings; using pokenae.Commons.Repositories; using pokenae.Commons.Repositories.impl; using pokenae.Commons.Services.Application; using pokenae.Commons.Services.Application.impl;

使用目的と意図

pokenae.Commons.Filters.LoggingActionFilter

LoggingActionFilterは、APIアクセスのログ記録を行うフィルタです。各アクションの実行前後にログを記録し、エラーハンドリングも行います。

pokenae.Commons.Filters.ApiAccessFilter

ApiAccessFilterは、ポケなえが管理するAPIに対してアクセス権限をチェックするフィルタです。特定のAPIエンドポイントにアクセスする前に、アクセス権限を確認します。

pokenae.Commons.Data.ApplicationDbContext

ApplicationDbContextは、データベースコンテキストクラスです。エンティティの保存、更新、削除などのデータベース操作を管理します。

pokenae.Commons.DTOs.BaseDto

BaseDtoは、データ転送オブジェクトの基底クラスです。エンティティのデータを転送するための共通プロパティを提供します。

pokenae.Commons.Entities.BaseEntity

BaseEntityは、エンティティの基底クラスです。作成者、作成日時、更新者、更新日時、削除者、削除日時などの共通プロパティを提供します。

pokenae.Commons.Mappings.BaseMappingProfile

BaseMappingProfileは、AutoMapperのマッピングプロファイルの基底クラスです。エンティティとDTOのマッピング設定を行います。

pokenae.Commons.Repositories.IEntityRepository

IEntityRepositoryは、エンティティのリポジトリインターフェースです。エンティティのCRUD操作を定義します。

pokenae.Commons.Repositories.impl.EntityRepository

EntityRepositoryは、IEntityRepositoryの実装クラスです。エンティティのCRUD操作を実装します。

pokenae.Commons.Services.Application.IApplicationService

IApplicationServiceは、アプリケーションサービスのインターフェースです。DTOを使用したビジネスロジックを定義します。

pokenae.Commons.Services.Application.impl.ApplicationService

ApplicationServiceは、IApplicationServiceの実装クラスです。DTOを使用したビジネスロジックを実装します。

実際の使用例

LoggingActionFilterの使用例

LoggingActionFilterをASP.NET Coreのフィルタとして使用する例を示します。

public void ConfigureServices(IServiceCollection services) { services.AddHttpClient(); services.AddScoped<LoggingActionFilter>(); services.AddControllers(options ⇒ { options.Filters.Add<LoggingActionFilter>(); }); }

ApiAccessFilterの使用例

ApiAccessFilterをASP.NET Coreのフィルタとして使用する例を示します。

public void ConfigureServices(IServiceCollection services) { services.AddHttpClient(); services.AddScoped<ApiAccessFilter>(); services.AddControllers(options ⇒ { options.Filters.Add<ApiAccessFilter>(); }); }

ApplicationDbContextの使用例

ApplicationDbContextを設定し、依存性注入する例を示します。

public void ConfigureServices(IServiceCollection services) { services.AddDbContext<ApplicationDbContext<YourDbContext>>(options ⇒ options.UseSqlServer(Configuration.GetConnectionString("DefaultConnection"))); services.AddHttpContextAccessor(); }

EntityRepositoryの使用例

EntityRepositoryを使用してエンティティのCRUD操作を行う例を示します。

public class YourService { private readonly IEntityRepository<YourEntity> _repository; public YourService(IEntityRepository<YourEntity> repository) { _repository = repository; }

public void AddEntity(YourDto dto) { var entity = new YourEntity { // DTOからエンティティへのマッピング }; _repository.Add(entity); }

public YourDto GetEntity(Guid id) { var entity = _repository.Find(e ⇒ e.Id == id); return new YourDto { // エンティティからDTOへのマッピング }; } }

拡張方法

IEntityRepositoryの拡張

IEntityRepositoryを拡張するには、新しいメソッドをインターフェースに追加します。

public interface IEntityRepository<T> where T : BaseEntity { // 既存のメソッド // 新しいメソッド Task<T> FindAsync(Func<T, bool> predicate); }

EntityRepositoryの拡張

EntityRepositoryを拡張するには、IEntityRepositoryで定義した新しいメソッドを実装します。

public class EntityRepository<T> : IEntityRepository<T> where T : BaseEntity { // 既存のメソッド public async Task<T> FindAsync(Func<T, bool> predicate) { return await Task.Run(() ⇒ _context.Set<T>().FirstOrDefault(predicate)); } }

IEntityServiceの拡張

IEntityServiceを拡張するには、新しいメソッドをインターフェースに追加します。

public interface IEntityService<T> where T : BaseEntity { // 既存のメソッド // 新しいメソッド Task<T> FindAsync(Func<T, bool> predicate); }

EntityServiceの拡張

EntityServiceを拡張するには、IEntityServiceで定義した新しいメソッドを実装します。

public class EntityService<T> : IEntityService<T> where T : BaseEntity { // 既存のメソッド public async Task<T> FindAsync(Func<T, bool> predicate) { return await repository.FindAsync(predicate); } }

BaseMappingProfileの拡張

BaseMappingProfileを拡張するには、新しいマッピング設定を追加します。

public class CustomMappingProfile : BaseMappingProfile { public CustomMappingProfile() { CreateMap<YourEntity, YourDto>(); CreateMap<YourDto, YourEntity>(); } }

まとめ

pokenae.Commonsプロジェクトは、共通の機能を提供することで、他のプロジェクトでのコードの再利用性を高め、開発効率を向上させることを目的としています。各クラスやインターフェースを適切に参照し、利用することで、共通のビジネスロジックやデータ操作を簡単に実装することができます。

Product Compatible and additional computed target framework versions.
.NET net8.0 is compatible.  net8.0-android was computed.  net8.0-browser was computed.  net8.0-ios was computed.  net8.0-maccatalyst was computed.  net8.0-macos was computed.  net8.0-tvos was computed.  net8.0-windows was computed.  net9.0 was computed.  net9.0-android was computed.  net9.0-browser was computed.  net9.0-ios was computed.  net9.0-maccatalyst was computed.  net9.0-macos was computed.  net9.0-tvos was computed.  net9.0-windows was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last updated
1.0.27 57 12 days ago
1.0.26 55 12 days ago
1.0.25 123 13 days ago
1.0.24 131 13 days ago
1.0.23 122 13 days ago
1.0.22 124 13 days ago
1.0.21 123 13 days ago
1.0.20 128 15 days ago
1.0.19 128 17 days ago
1.0.18 126 17 days ago
1.0.17 124 17 days ago
1.0.16 119 18 days ago
1.0.15 134 18 days ago
1.0.14 119 18 days ago
1.0.13 117 18 days ago
1.0.12 125 18 days ago
1.0.11 118 18 days ago
1.0.10 118 18 days ago
1.0.9 56 19 days ago
1.0.8 193 a month ago
1.0.7 191 a month ago
1.0.6 194 a month ago
1.0.5 196 a month ago
1.0.4 187 a month ago
1.0.3 184 a month ago
1.0.2 184 a month ago
1.0.1 199 a month ago
1.0.0 192 a month ago