Skip to content

Commit 961338d

Browse files
committed
Update README.md
1 parent 25142a2 commit 961338d

File tree

1 file changed

+22
-29
lines changed

1 file changed

+22
-29
lines changed

README.md

Lines changed: 22 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,10 @@
33
[![NuGet version](https://img.shields.io/nuget/v/BitzArt.XDoc.svg)](https://www.nuget.org/packages/BitzArt.XDoc/)
44
[![NuGet downloads](https://img.shields.io/nuget/dt/BitzArt.XDoc.svg)](https://www.nuget.org/packages/BitzArt.XDoc/)
55

6-
# Overview
6+
A lightweight and efficient tool for parsing and managing C# XML documentation comments.
77

8-
A lightweight and efficient tool for parsing, and managing C# XML documentation comments.
98

10-
11-
### BitzArt.XDoc
9+
# BitzArt.XDoc
1210

1311
BitzArt.XDoc is a lightweight .NET library for parsing and accessing XML documentation comments from your C# code. It provides an intuitive API to retrieve documentation for:
1412
* Types/classes
@@ -28,7 +26,7 @@ var typeDocs = xdoc.Get(typeof(MyType));
2826
var propertyDocs = xDoc.Get(typeof(MyType).GetProperty(nameof(MyType.PropertyOne)));
2927
```
3028

31-
### BitzArt.XDoc.PlainText
29+
# BitzArt.XDoc.PlainText
3230

3331
BitzArt.XDoc.PlainText is an extension package for BitzArt.XDoc that enables rendering XML documentation
3432
comments into plain text.
@@ -47,60 +45,55 @@ var propertyDescrption = xDoc.Get(typeof(MyType).GetProperty(nameof(MyType.Prope
4745

4846
```
4947

50-
51-
### BitzArt.XDoc.EntityFrameworkCore
52-
53-
#### Features:
48+
# BitzArt.XDoc.EntityFrameworkCore
5449

5550
BitzArt.XDoc.EntityFrameworkCore is an extension library that bridges XML documentation comments from C#
5651
code to Entity Framework Core database objects.
5752

53+
5854
Example 1: Configure comments for all entities in your DbContext
5955

6056
```csharp
6157
using BitzArt.XDoc;
62-
using Xdoc.Renderer.PlaintText;
63-
using BitzArt.XDoc.EntityFrameworkCore
64-
...
65-
66-
services.AddScoped<EntitiesCommentConfigurator>();
67-
68-
...
6958

7059
public class MyDbContext : DbContext
7160
{
72-
private readonly EntitiesCommentConfigurator _commentConfigurator;
73-
74-
public MyDbContext(DbContextOptions options, EntitiesCommentConfigurator commentConfigurator) : base(options)
75-
{
76-
_commentConfigurator = commentConfigurator;
77-
}
78-
7961
protected override void OnModelCreating(ModelBuilder modelBuilder)
8062
{
8163
base.OnModelCreating(modelBuilder);
8264

8365
// Configure comments for all entities
84-
_commentConfigurator.ConfigureComments(modelBuilder);
66+
modelBuilder.ConfigureComments(new XDoc());
8567
}
8668
}
8769
```
8870

89-
9071
Example 2: Configure comments for specific properties using Fluent API
9172

92-
9373
```csharp
9474
using BitzArt.XDoc;
95-
using Xdoc.Renderer.PlaintText;
96-
using BitzArt.XDoc.EntityFrameworkCore
9775

9876
...
9977

10078
protected override void OnModelCreating(ModelBuilder modelBuilder)
10179
{
10280
modelBuilder.Entity<Customer>()
10381
.Property(c => c.Name)
104-
.MapPropertyComment<string, Customer>(c => c.Name);
82+
.HasComment<string, Customer>(c => c.Name);
10583
}
10684
```
85+
86+
## Recommendations
87+
Each XDoc instance maintains its own cache of parsed documentation in a `ConcurrentDictionary<Assembly, AssemblyDocumentation>`. Using multiple instances unnecessarily duplicates this data in memory
88+
89+
If your application provides documentation-related services (like API documentation generation), maintaining a single pre-loaded XDoc instance can significantly improve response times.
90+
91+
### Possible approaches
92+
93+
#### Dependency Injection (Recommended)
94+
Register XDoc as a singleton in your application's dependency injection container.
95+
96+
#### Factory
97+
Create a factory that provides access to a shared XDoc instance:
98+
99+
By following these recommendations, you can ensure that XML documentation is parsed only once per assembly, maximizing performance and minimizing resource usage in your application.

0 commit comments

Comments
 (0)