Skip to content

Commit 35a851e

Browse files
committed
refactor: Remove InMemory Storage Provider
1 parent 5acfddc commit 35a851e

File tree

14 files changed

+122
-405
lines changed

14 files changed

+122
-405
lines changed

docs/Setup/Configuration.md

+36-36
Large diffs are not rendered by default.

docs/Storage/Readme.md

+10-2
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,21 @@
22

33
Currently, there are 5 Storage-Provider:
44

5-
- InMemory - Basically a list holding your data (per request). If the User hits a hard reload, the data is gone.
65
- RavenDb - As the name suggests for RavenDb. RavenDb automatically creates all the documents, if a database name is provided.
6+
- MongoDB - Based on the official MongoDB driver. The database and collection are automatically created.
77
- Sqlite - Based on EF Core, it can be easily adapted for other Sql Dialects. The tables are automatically created.
88
- SqlServer - Based on EF Core, it can be easily adapted for other Sql Dialects. The tables are automatically created.
99
- MySql - Based on EF Core - also supports MariaDB.
1010

11-
The default (when you clone the repository) is the `InMemory` option. That means every time you restart the service, all posts and related objects are gone.
11+
The default (when you clone the repository) is the `Sqlite` option with an in-memory database.
12+
That means every time you restart the service, all posts and related objects are gone. This is useful for testing.
13+
If you want to persist the data with Sqlite, you can change the `appsettings.json` file to:
14+
15+
```json
16+
{
17+
"PersistenceProvider": "Sqlite",
18+
"ConnectionString": "Data Source=blog.db",
19+
```
1220

1321
Note the ConnectionString format of SQL Server needs to be consistent:
1422

src/LinkDotNet.Blog.Infrastructure/Persistence/InMemory/PaginatedListQueryExtensions.cs

-26
This file was deleted.

src/LinkDotNet.Blog.Infrastructure/Persistence/InMemory/Repository.cs

-104
This file was deleted.

src/LinkDotNet.Blog.Infrastructure/Persistence/PersistenceProvider.cs

-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ public sealed class PersistenceProvider : Enumeration<PersistenceProvider>
77
public static readonly PersistenceProvider SqlServer = new(nameof(SqlServer));
88
public static readonly PersistenceProvider Sqlite = new(nameof(Sqlite));
99
public static readonly PersistenceProvider RavenDb = new(nameof(RavenDb));
10-
public static readonly PersistenceProvider InMemory = new(nameof(InMemory));
1110
public static readonly PersistenceProvider MySql = new(nameof(MySql));
1211
public static readonly PersistenceProvider MongoDB = new(nameof(MongoDB));
1312

src/LinkDotNet.Blog.Web/RegistrationExtensions/InMemoryRegistrationExtensions.cs

-14
This file was deleted.

src/LinkDotNet.Blog.Web/RegistrationExtensions/StorageProviderExtensions.cs

+1-6
Original file line numberDiff line numberDiff line change
@@ -18,12 +18,7 @@ public static IServiceCollection AddStorageProvider(this IServiceCollection serv
1818
var provider = configuration["PersistenceProvider"] ?? throw new InvalidOperationException("No persistence provider configured");
1919
var persistenceProvider = PersistenceProvider.Create(provider);
2020

21-
if (persistenceProvider == PersistenceProvider.InMemory)
22-
{
23-
services.UseInMemoryAsStorageProvider();
24-
services.RegisterCachedRepository<Infrastructure.Persistence.InMemory.Repository<BlogPost>>();
25-
}
26-
else if (persistenceProvider == PersistenceProvider.RavenDb)
21+
if (persistenceProvider == PersistenceProvider.RavenDb)
2722
{
2823
services.UseRavenDbAsStorageProvider();
2924
services.RegisterCachedRepository<Infrastructure.Persistence.RavenDb.Repository<BlogPost>>();

src/LinkDotNet.Blog.Web/appsettings.json

+2-2
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,8 @@
1919
"BackgroundUrl": "assets/profile-background.webp",
2020
"ProfilePictureUrl": "assets/profile-picture.webp"
2121
},
22-
"PersistenceProvider": "InMemory",
23-
"ConnectionString": "",
22+
"PersistenceProvider": "Sqlite",
23+
"ConnectionString": "DataSource=file::memory:?cache=shared",
2424
"DatabaseName": "",
2525
"Authentication": {
2626
"Provider": "Auth0",

tests/LinkDotNet.Blog.IntegrationTests/SmokeTests.cs

+2-1
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,8 @@ public SmokeTests(WebApplicationFactory<Program> factory)
1515
{
1616
this.factory = factory.WithWebHostBuilder(builder =>
1717
{
18-
builder.UseSetting("PersistenceProvider", PersistenceProvider.InMemory.Key);
18+
builder.UseSetting("PersistenceProvider", PersistenceProvider.Sqlite.Key);
19+
builder.UseSetting("ConnectionString", "DataSource=file::memory:?cache=shared");
1920
});
2021
}
2122

0 commit comments

Comments
 (0)