eXtensionSharp.Mongo
0.0.2
See the version list below for details.
dotnet add package eXtensionSharp.Mongo --version 0.0.2
NuGet\Install-Package eXtensionSharp.Mongo -Version 0.0.2
<PackageReference Include="eXtensionSharp.Mongo" Version="0.0.2" />
<PackageVersion Include="eXtensionSharp.Mongo" Version="0.0.2" />
<PackageReference Include="eXtensionSharp.Mongo" />
paket add eXtensionSharp.Mongo --version 0.0.2
#r "nuget: eXtensionSharp.Mongo, 0.0.2"
#:package eXtensionSharp.Mongo@0.0.2
#addin nuget:?package=eXtensionSharp.Mongo&version=0.0.2
#tool nuget:?package=eXtensionSharp.Mongo&version=0.0.2
๐ฆ eXtensionSharp.Mongo
MongoDB๋ฅผ .NET ํ๋ก์ ํธ์์ ํ์
์์ ํ๊ณ ์ ์ธ์ ์ผ๋ก ์ฌ์ฉํ ์ ์๋๋ก ๋์์ฃผ๋ ๊ฒฝ๋ ๋ํผ ๋ผ์ด๋ธ๋ฌ๋ฆฌ์
๋๋ค.
JMongo<T>
, IJMongoFactory
, ์ธ๋ฑ์ค ์๋ ์ด๊ธฐํ ๊ธฐ๋ฅ์ ์ง์ํ๋ฉฐ, DI ๊ธฐ๋ฐ์ผ๋ก ์ ์ฐํ๊ฒ ๊ตฌ์ฑํ ์ ์์ต๋๋ค.
โจ ์ฃผ์ ๊ธฐ๋ฅ
JMongo<T>
: ์ปฌ๋ ์ ์ ๊ทผ์ ์ ๋ค๋ฆญ ๊ธฐ๋ฐ์ผ๋ก ๋จ์ํIJMongoFactory
: ํ์ ๊ธฐ๋ฐ์ผ๋ก ์ปฌ๋ ์ ์๋ ์์ฑ[JMongoCollection]
: ์ปฌ๋ ์ ๋ฐ DB ์ ๋ณด ์์ฑ์ผ๋ก ์ ์ธAddInitializer(...)
: ์ธ๋ฑ์ค ์ ์๋ฅผ ์ฝ๋ ๋๋ ๊ตฌํ์ฒด ๊ธฐ๋ฐ์ผ๋ก ๊ตฌ์ฑUseJMongoDbAsync()
: ์ฑ ์์ ์ ์ธ๋ฑ์ค ์๋ ์์ฑ ์คํ
๐ง ์ค์น
dotnet add package MongoDB.Driver
๐ ์ด ๋ผ์ด๋ธ๋ฌ๋ฆฌ๋ MongoDB.Driver๋ฅผ ํ์๋ก ํ๋ฉฐ, .NET 6 ์ด์์์ ์ฌ์ฉ ๊ฐ๋ฅํฉ๋๋ค.
๐งฑ ๊ธฐ๋ณธ ๊ตฌ์กฐ
1. ๋ชจ๋ธ ์ ์
[JMongoCollection("AppDb", "sample_collection")]
public class SampleDocument
{
[BsonId]
[BsonRepresentation(BsonType.ObjectId)]
public string Id { get; set; }
[BsonElement("createdAt")]
public DateTime CreatedAt { get; set; }
}
2. ์ธ๋ฑ์ค ์ด๊ธฐํ ํด๋์ค
public class SampleDocumentIndexInitializer : IJMongoIndexInitializer
{
public async Task InitializeIndexesAsync(IServiceProvider provider)
{
var factory = provider.GetRequiredService<IJMongoFactory>();
var col = factory.Create<SampleDocument>().GetCollection();
await col.Indexes.CreateOneAsync(
new CreateIndexModel<SampleDocument>(
Builders<SampleDocument>.IndexKeys.Ascending(x => x.CreatedAt),
new CreateIndexOptions { ExpireAfter = TimeSpan.FromDays(90) }
)
);
}
}
3. DI ๊ตฌ์ฑ (Program.cs
๋๋ Startup.cs
)
builder.Services.AddJMongoDb("mongodb://localhost:27017", options =>
{
// ํ์
๊ธฐ๋ฐ ๋ฑ๋ก (ํด๋์ค๋ DI ์๋ ๋ฑ๋ก๋จ)
options.AddInitializer<SampleDocumentIndexInitializer>();
// ๋๋ ๋๋ค ๋ฐฉ์์ผ๋ก ์ง์ ๋ฑ๋ก๋ ๊ฐ๋ฅ
options.AddInitializer(async provider =>
{
var factory = provider.GetRequiredService<IJMongoFactory>();
var col = factory.Create<AnotherDocument>().GetCollection();
await col.Indexes.CreateOneAsync(new CreateIndexModel<AnotherDocument>(
Builders<AnotherDocument>.IndexKeys.Ascending(x => x.Timestamp)
));
});
});
4. ์ฑ ์์ ์ ์ธ๋ฑ์ค ์ด๊ธฐํ ์คํ
var app = builder.Build();
await app.Services.UseJMongoDbAsync(); // ์ธ๋ฑ์ค ์๋ ์์ฑ
app.Run();
๐งฉ ์ฃผ์ ์ธํฐํ์ด์ค ์์ฝ
์ธํฐํ์ด์ค | ์ค๋ช |
---|---|
IJMongoFactory |
T ํ์
์ ๋ถ์ฌ๋ JMongoCollectionAttribute ๋ฅผ ๊ธฐ๋ฐ์ผ๋ก ์ปฌ๋ ์
์ ์์ฑ |
IJMongoIndexInitializer |
์ธ๋ฑ์ค ์์ฑ ์ ์ ์ธํฐํ์ด์ค |
IJMongoIndexInitializerRunner |
๋ฑ๋ก๋ ์ด๊ธฐํ ์์ ๋ค์ ์คํํ๋ ์คํ๊ธฐ |
๐ ํต์ฌ ๊ตฌ์ฑ ์์
JMongo<T>
: ์ปฌ๋ ์ ์ ๊ทผ์ ์ถ์ํJMongoFactory
: ๋ฆฌํ๋ ์ ๊ธฐ๋ฐ์ผ๋ก ์ปฌ๋ ์ ์ค์ ์ถ์ถJMongoDbOptions
: ์ธ๋ฑ์ค ์ ์ ์์ง ์ปจํ ์ด๋DependencyInjection
: ์๋น์ค ๋ฑ๋ก ๋ฐ ์ธ๋ฑ์ค ์คํ ๋ฉ์๋
โ ๋ผ์ด์ ์ค
MIT License (์์ ๋กญ๊ฒ ์ฌ์ฉ ๋ฐ ์์ ๊ฐ๋ฅ)
๐จโ๐ป ๊ฐ๋ฐ ๊ธฐ์ฌ
Pull Request ๋ฐ ์ด์ ํ์ํฉ๋๋ค.
๊ตฌ์กฐ ๊ฐ์ , ๊ธฐ๋ฅ ํ์ฅ(์: Attribute ๊ธฐ๋ฐ Index ์ ์, Migration ์ง์ ๋ฑ) ์ ์๋ ์ ๊ทน ์์ฉํฉ๋๋ค.
Product | Versions 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 is compatible. 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. net10.0 was computed. net10.0-android was computed. net10.0-browser was computed. net10.0-ios was computed. net10.0-maccatalyst was computed. net10.0-macos was computed. net10.0-tvos was computed. net10.0-windows was computed. |
-
net8.0
- MongoDB.Bson (>= 3.4.0)
- MongoDB.Driver (>= 3.4.0)
-
net9.0
- MongoDB.Bson (>= 3.4.0)
- MongoDB.Driver (>= 3.4.0)
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.