Skip to content

🐛 Inject IMudMarkdownMemoryCache into MudMarkdownValueProvider#313

Merged
MihailsKuzmins merged 2 commits into
MyNihongo:mainfrom
MattParkerDev:fix-cache-di
Jun 2, 2025
Merged

🐛 Inject IMudMarkdownMemoryCache into MudMarkdownValueProvider#313
MihailsKuzmins merged 2 commits into
MyNihongo:mainfrom
MattParkerDev:fix-cache-di

Conversation

@MattParkerDev

@MattParkerDev MattParkerDev commented May 17, 2025

Copy link
Copy Markdown
Contributor

Fixes #311

Tests pass, I haven't tested any further than that.

@MihailsKuzmins MihailsKuzmins left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@MattParkerDev thanks. It looks like bUnit also registers an IMemoryCache, therefore, unit tests have not been able to catch this error and IMemoryCache was successfully injected into MudMarkdownValueProvider.

Therefore, could you please add a new unit test to prevent this error from happening in MudBlazor.Markdown.Tests?
Utils/ServiceCollectionExTests/AddMudMarkdownServicesShould.cs
※ please use tabs for indentation.

namespace MudBlazor.Markdown.Tests.Utils.ServiceCollectionExTests;

public sealed class AddMudMarkdownServicesShould
{
	[Fact]
	public void RegisterServices()
	{
		using var serviceProvider = new ServiceCollection()
			.AddMudMarkdownServices()
			.BuildServiceProvider();

		serviceProvider.GetRequiredService<IMudMarkdownMemoryCache>()
			.Should()
			.BeOfType<MudMarkdownMemoryCache>();

		serviceProvider.GetService<IMemoryCache>()
			.Should()
			.BeNull();

		serviceProvider.GetRequiredService<IMudMarkdownThemeService>()
			.Should()
			.BeOfType<MudMarkdownThemeService>();

		serviceProvider.GetRequiredService<IMudMarkdownValueProvider>()
			.Should()
			.BeOfType<MudMarkdownValueProvider>();
	}
}

@MattParkerDev

Copy link
Copy Markdown
Contributor Author

@MihailsKuzmins test added :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Unable to construct MudMarkdownValueProvider without explicit addition of AddMemoryCache()

2 participants