Skip to content

Commit

Permalink
refactor: Remove InMemory Storage Provider
Browse files Browse the repository at this point in the history
  • Loading branch information
linkdotnet committed Oct 11, 2024
1 parent 5acfddc commit 35a851e
Show file tree
Hide file tree
Showing 14 changed files with 122 additions and 405 deletions.
72 changes: 36 additions & 36 deletions docs/Setup/Configuration.md

Large diffs are not rendered by default.

12 changes: 10 additions & 2 deletions docs/Storage/Readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,21 @@

Currently, there are 5 Storage-Provider:

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

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.
The default (when you clone the repository) is the `Sqlite` option with an in-memory database.
That means every time you restart the service, all posts and related objects are gone. This is useful for testing.
If you want to persist the data with Sqlite, you can change the `appsettings.json` file to:

```json
{
"PersistenceProvider": "Sqlite",
"ConnectionString": "Data Source=blog.db",
```

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

Expand Down

This file was deleted.

104 changes: 0 additions & 104 deletions src/LinkDotNet.Blog.Infrastructure/Persistence/InMemory/Repository.cs

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ public sealed class PersistenceProvider : Enumeration<PersistenceProvider>
public static readonly PersistenceProvider SqlServer = new(nameof(SqlServer));
public static readonly PersistenceProvider Sqlite = new(nameof(Sqlite));
public static readonly PersistenceProvider RavenDb = new(nameof(RavenDb));
public static readonly PersistenceProvider InMemory = new(nameof(InMemory));
public static readonly PersistenceProvider MySql = new(nameof(MySql));
public static readonly PersistenceProvider MongoDB = new(nameof(MongoDB));

Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,7 @@ public static IServiceCollection AddStorageProvider(this IServiceCollection serv
var provider = configuration["PersistenceProvider"] ?? throw new InvalidOperationException("No persistence provider configured");
var persistenceProvider = PersistenceProvider.Create(provider);

if (persistenceProvider == PersistenceProvider.InMemory)
{
services.UseInMemoryAsStorageProvider();
services.RegisterCachedRepository<Infrastructure.Persistence.InMemory.Repository<BlogPost>>();
}
else if (persistenceProvider == PersistenceProvider.RavenDb)
if (persistenceProvider == PersistenceProvider.RavenDb)
{
services.UseRavenDbAsStorageProvider();
services.RegisterCachedRepository<Infrastructure.Persistence.RavenDb.Repository<BlogPost>>();
Expand Down
4 changes: 2 additions & 2 deletions src/LinkDotNet.Blog.Web/appsettings.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@
"BackgroundUrl": "assets/profile-background.webp",
"ProfilePictureUrl": "assets/profile-picture.webp"
},
"PersistenceProvider": "InMemory",
"ConnectionString": "",
"PersistenceProvider": "Sqlite",
"ConnectionString": "DataSource=file::memory:?cache=shared",
"DatabaseName": "",
"Authentication": {
"Provider": "Auth0",
Expand Down
3 changes: 2 additions & 1 deletion tests/LinkDotNet.Blog.IntegrationTests/SmokeTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@ public SmokeTests(WebApplicationFactory<Program> factory)
{
this.factory = factory.WithWebHostBuilder(builder =>
{
builder.UseSetting("PersistenceProvider", PersistenceProvider.InMemory.Key);
builder.UseSetting("PersistenceProvider", PersistenceProvider.Sqlite.Key);
builder.UseSetting("ConnectionString", "DataSource=file::memory:?cache=shared");
});
}

Expand Down
Loading

0 comments on commit 35a851e

Please sign in to comment.