From 6a7b7a989172a03276ccb7e1eaefd5d4beabce68 Mon Sep 17 00:00:00 2001 From: tekgator Date: Sat, 3 Jun 2023 09:09:28 +1000 Subject: [PATCH 1/4] Renamed MinecraftJarManager to MinecraftJar --- .../MinecraftJars.Demo.Console/Program.cs | 4 ++-- MinecraftJars.Tests/DownloadTests.cs | 12 +++++----- MinecraftJars.Tests/ProjectTests.cs | 12 +++++----- MinecraftJars.Tests/ProviderTests.cs | 14 ++++++------ MinecraftJars.Tests/VersionTests.cs | 14 ++++++------ ...MinecraftJarManager.cs => MinecraftJar.cs} | 22 ++----------------- 6 files changed, 30 insertions(+), 48 deletions(-) rename MinecraftJars/{MinecraftJarManager.cs => MinecraftJar.cs} (74%) diff --git a/MinecraftJars.Demo/MinecraftJars.Demo.Console/Program.cs b/MinecraftJars.Demo/MinecraftJars.Demo.Console/Program.cs index 47543c0..dd78efc 100644 --- a/MinecraftJars.Demo/MinecraftJars.Demo.Console/Program.cs +++ b/MinecraftJars.Demo/MinecraftJars.Demo.Console/Program.cs @@ -2,9 +2,9 @@ using MinecraftJars; using MinecraftJars.Core.Versions; -var providerManager = new MinecraftJarManager(); +var minecraftJar = new MinecraftJar(); -foreach (var provider in providerManager.GetProviders()) +foreach (var provider in minecraftJar.GetProviders()) { SetConsoleColor(ConsoleColor.White, ConsoleColor.Red); Console.WriteLine($"{provider.Name}:"); diff --git a/MinecraftJars.Tests/DownloadTests.cs b/MinecraftJars.Tests/DownloadTests.cs index 3687bb6..d367371 100644 --- a/MinecraftJars.Tests/DownloadTests.cs +++ b/MinecraftJars.Tests/DownloadTests.cs @@ -8,9 +8,9 @@ namespace MinecraftJars.Tests; [TestFixture, Order(4)] public class DownloadTests { - private static readonly MinecraftJarManager JarManager = new(); + private static readonly MinecraftJar MinecraftJar = new(); private static IEnumerable Projects() => - JarManager.GetProviders().SelectMany(p => p.Projects.Select(t => t.Name)); + MinecraftJar.GetProviders().SelectMany(p => p.Projects.Select(t => t.Name)); [Test, Order(1)] [Ignore("Very time consuming should only be utilised when necessary")] @@ -18,7 +18,7 @@ public async Task GetDownloads_Success( [ValueSource(nameof(Projects))] string projectName, [Values(true, false)] bool loadFileSize) { - var project = JarManager.GetProjects().Single(p => p.Name.Equals(projectName)); + var project = MinecraftJar.GetProjects().Single(p => p.Name.Equals(projectName)); foreach (var version in await project.GetVersions()) { @@ -42,7 +42,7 @@ public async Task GetDownloads_LatestVersion( [ValueSource(nameof(Projects))] string projectName, [Values(true, false)] bool loadFileSize) { - var project = JarManager.GetProjects().Single(p => p.Name.Equals(projectName)); + var project = MinecraftJar.GetProjects().Single(p => p.Name.Equals(projectName)); var version = (await project.GetVersions(new VersionOptions { MaxRecords = 1 })).First(); TestContext.Progress.WriteLine("{0}: Retrieving download for version {1}", @@ -63,7 +63,7 @@ public async Task GetDownloads_LatestVersion( [Ignore("Very time consuming should only be utilised when necessary. Git and Java must be installed")] public async Task BuildSpigot_Success(string projectName) { - var project = JarManager.GetProjects().Single(p => p.Name.Equals(projectName)); + var project = MinecraftJar.GetProjects().Single(p => p.Name.Equals(projectName)); var version = (await project.GetVersions(new VersionOptions { MaxRecords = 1 })).First(); TestContext.Progress.WriteLine("{0}: Start building {1} version {2}", @@ -98,7 +98,7 @@ public async Task BuildSpigot_Success(string projectName) [Ignore("Very time consuming should only be utilised when necessary. Git and Java must be installed")] public async Task BuildSpigot_Cancel(string projectName) { - var project = JarManager.GetProjects().Single(p => p.Name.Equals(projectName)); + var project = MinecraftJar.GetProjects().Single(p => p.Name.Equals(projectName)); var version = (await project.GetVersions(new VersionOptions { MaxRecords = 1 })).First(); TestContext.Progress.WriteLine("{0}: Start building {1} version {2}", diff --git a/MinecraftJars.Tests/ProjectTests.cs b/MinecraftJars.Tests/ProjectTests.cs index 4b193c6..0befda5 100644 --- a/MinecraftJars.Tests/ProjectTests.cs +++ b/MinecraftJars.Tests/ProjectTests.cs @@ -5,18 +5,18 @@ namespace MinecraftJars.Tests; [TestFixture, Order(2)] public class ProjectTests { - private static readonly MinecraftJarManager JarManager = new(); - private static IEnumerable Providers() => JarManager.GetProviders().Select(p => p.Name); + private static readonly MinecraftJar MinecraftJar = new(); + private static IEnumerable Providers() => MinecraftJar.GetProviders().Select(p => p.Name); private static IEnumerable Groups() => Enum.GetValues(); [TestCaseSource(nameof(Providers)), Order(1)] public void GetProviderByProject_Success(string providerName) { - var provider = JarManager.GetProvider(providerName); + var provider = MinecraftJar.GetProvider(providerName); foreach (var project in provider.Projects) { - var providerByProject = JarManager.GetProvider(project); + var providerByProject = MinecraftJar.GetProvider(project); Assert.That(providerByProject, Is.SameAs(provider)); TestContext.Progress.WriteLine("{0}: Provider for project {1} is {2}", @@ -27,7 +27,7 @@ public void GetProviderByProject_Success(string providerName) [TestCase, Order(2)] public void GetProjects_Success() { - var projects = JarManager.GetProjects().ToList(); + var projects = MinecraftJar.GetProjects().ToList(); Assert.That(projects, Is.Not.Empty); TestContext.Progress.WriteLine("{0}: {1} projects found", nameof(GetProjects_Success), projects.Count); @@ -36,7 +36,7 @@ public void GetProjects_Success() [TestCaseSource(nameof(Groups)), Order(3)] public void GetProjectsByGroup_Success(Group group) { - var projects = JarManager.GetProjects(group).ToList(); + var projects = MinecraftJar.GetProjects(group).ToList(); Assert.That(projects.All(p => p.Group == group), Is.True); TestContext.Progress.WriteLine("{0}: {1} projects found for {2}", nameof(GetProjectsByGroup_Success), projects.Count, group); diff --git a/MinecraftJars.Tests/ProviderTests.cs b/MinecraftJars.Tests/ProviderTests.cs index bccbbbd..cd4c78e 100644 --- a/MinecraftJars.Tests/ProviderTests.cs +++ b/MinecraftJars.Tests/ProviderTests.cs @@ -5,13 +5,13 @@ namespace MinecraftJars.Tests; [TestFixture, Order(1)] public class ProviderTests { - private static readonly MinecraftJarManager JarManager = new(); + private static readonly MinecraftJar MinecraftJar = new(); private static IEnumerable Groups() => Enum.GetValues(); [TestCase, Order(1)] public void GetProviders_Success() { - var providers = JarManager.GetProviders().ToList(); + var providers = MinecraftJar.GetProviders().ToList(); Assert.That(providers, Is.Not.Empty); TestContext.Progress.WriteLine("{0}: {1} providers found", nameof(GetProviders_Success), providers.Count); @@ -20,7 +20,7 @@ public void GetProviders_Success() [TestCaseSource(nameof(Groups)), Order(2)] public void GetProvidersByGroup_Success(Group group) { - var providers = JarManager.GetProviders(group).ToList(); + var providers = MinecraftJar.GetProviders(group).ToList(); Assert.That(providers, Is.Not.Empty); TestContext.Progress.WriteLine("{0}: {1} providers found for {2}", nameof(GetProvidersByGroup_Success), providers.Count, group); @@ -29,16 +29,16 @@ public void GetProvidersByGroup_Success(Group group) [TestCase(100), Order(3)] public void GetProvidersByGroup_InvalidGroup(Group group) { - Assert.That(JarManager.GetProviders(group), Is.Empty); + Assert.That(MinecraftJar.GetProviders(group), Is.Empty); TestContext.Progress.WriteLine("{0}: Group {1} is invalid", nameof(GetProvidersByGroup_InvalidGroup), group); } [TestCase, Order(4)] public void GetProviderByName_Success() { - foreach (var name in JarManager.GetProviders().Select(p => p.Name)) + foreach (var name in MinecraftJar.GetProviders().Select(p => p.Name)) { - var provider = JarManager.GetProvider(name); + var provider = MinecraftJar.GetProvider(name); Assert.That(provider, Is.Not.Null); TestContext.Progress.WriteLine("{0}: Provider for name {1} found", nameof(GetProviderByName_Success), name); @@ -48,7 +48,7 @@ public void GetProviderByName_Success() [TestCase("InvalidProviderName"), Order(5)] public void GetProviderByName_InvalidProvider(string name) { - Assert.Throws(() => JarManager.GetProvider(name)); + Assert.Throws(() => MinecraftJar.GetProvider(name)); TestContext.Progress.WriteLine("{0}: Provider name {1} invalid", nameof(GetProviderByName_InvalidProvider), name); } } \ No newline at end of file diff --git a/MinecraftJars.Tests/VersionTests.cs b/MinecraftJars.Tests/VersionTests.cs index 42b1741..65cd49f 100644 --- a/MinecraftJars.Tests/VersionTests.cs +++ b/MinecraftJars.Tests/VersionTests.cs @@ -6,14 +6,14 @@ namespace MinecraftJars.Tests; [TestFixture, Order(3)] public class VersionTests { - private static readonly MinecraftJarManager JarManager = new MinecraftJarManager(); + private static readonly MinecraftJar MinecraftJar = new(); private static IEnumerable Projects() => - JarManager.GetProviders().SelectMany(p => p.Projects.Select(t => t.Name)); + MinecraftJar.GetProviders().SelectMany(p => p.Projects.Select(t => t.Name)); [TestCaseSource(nameof(Projects)), Order(1)] public async Task GetVersions_Success(string projectName) { - var project = JarManager.GetProjects().Single(p => p.Name.Equals(projectName)); + var project = MinecraftJar.GetProjects().Single(p => p.Name.Equals(projectName)); var versions = (await project.GetVersions()).ToList(); Assert.That(versions, Is.Not.Empty); @@ -28,7 +28,7 @@ public async Task GetVersions_MaxRecordsMax( [ValueSource(nameof(Projects))] string projectName, [Values(5, 10)] int maxRecords) { - var project = JarManager.GetProjects().Single(p => p.Name.Equals(projectName)); + var project = MinecraftJar.GetProjects().Single(p => p.Name.Equals(projectName)); var versions = (await project.GetVersions(new VersionOptions { MaxRecords = maxRecords @@ -43,7 +43,7 @@ public async Task GetVersions_MaxRecordsMax( [TestCaseSource(nameof(Projects)), Order(3)] public async Task GetVersions_SpecificVersion(string projectName) { - var project = JarManager.GetProjects().Single(p => p.Name.Equals(projectName)); + var project = MinecraftJar.GetProjects().Single(p => p.Name.Equals(projectName)); var version = (await project.GetVersions()).First(); var versions = (await project.GetVersions(new VersionOptions { @@ -69,7 +69,7 @@ public async Task GetVersions_SpecificVersion(string projectName) [Order(4)] public async Task GetVersions_ContainsSnapshot(string projectName) { - var project = JarManager.GetProjects().Single(p => p.Name.Equals(projectName)); + var project = MinecraftJar.GetProjects().Single(p => p.Name.Equals(projectName)); var versions = (await project.GetVersions(new VersionOptions { @@ -92,7 +92,7 @@ public async Task GetVersions_ContainsSnapshot(string projectName) [Order(5)] public async Task GetVersions_ContainsNoSnapshot(string projectName) { - var project = JarManager.GetProjects().Single(p => p.Name.Equals(projectName)); + var project = MinecraftJar.GetProjects().Single(p => p.Name.Equals(projectName)); var versions = (await project.GetVersions(new VersionOptions { IncludeSnapshotBuilds = false diff --git a/MinecraftJars/MinecraftJarManager.cs b/MinecraftJars/MinecraftJar.cs similarity index 74% rename from MinecraftJars/MinecraftJarManager.cs rename to MinecraftJars/MinecraftJar.cs index cc7045c..76cef83 100644 --- a/MinecraftJars/MinecraftJarManager.cs +++ b/MinecraftJars/MinecraftJar.cs @@ -7,7 +7,7 @@ namespace MinecraftJars; -public class MinecraftJarManager +public class MinecraftJar : IMinecraftJar { [ImportMany(typeof(IMinecraftProvider))] private IEnumerable _providers; @@ -18,7 +18,7 @@ public class MinecraftJarManager [Export] private PluginHttpClientFactory HttpClientFactory { get; } - public MinecraftJarManager(ProviderOptions? options = null) + public MinecraftJar(ProviderOptions? options = null) { ProviderOptions = options ?? new ProviderOptions(); HttpClientFactory = new PluginHttpClientFactory(ProviderOptions.HttpClientFactory); @@ -33,17 +33,11 @@ public MinecraftJarManager(ProviderOptions? options = null) _providers ??= Enumerable.Empty(); } - /// - /// Return a list of all providers (plugins) - /// public IEnumerable GetProviders() { return _providers; } - /// - /// Return a list of all providers offering a certain project group - /// public IEnumerable GetProviders(Group group) { var providers = new List(); @@ -54,36 +48,24 @@ public IEnumerable GetProviders(Group group) return providers; } - /// - /// Return a specific provider - /// public IMinecraftProvider GetProvider(string provider) { return _providers .Single(p => p.Name.Equals(provider)); } - /// - /// Return the provider for the provided Project - /// public IMinecraftProvider GetProvider(IMinecraftProject project) { return _providers .Single(p => p.Projects.Contains(project)); } - /// - /// Return a list of all projects (e.g. Vanilla, Spigot, etc.) - /// public IEnumerable GetProjects() { return GetProviders() .SelectMany(p => p.Projects); } - /// - /// Return a list of all projects for a certain type (e.g. all proxies) - /// public IEnumerable GetProjects(Group group) { return GetProviders() From e70f23f5923928b0fcb8546131f6db96e88aa279 Mon Sep 17 00:00:00 2001 From: tekgator Date: Sat, 3 Jun 2023 09:09:47 +1000 Subject: [PATCH 2/4] Add dependency injection package --- .github/workflows/build-and-publish.yml | 13 ++++-- CHANGELOG.md | 13 +++++- ...tJars.Extension.DependencyInjection.csproj | 42 +++++++++++++++++++ .../README.md | 18 ++++++++ .../ServiceCollectionExtensions.cs | 18 ++++++++ .../DependencyInjectionTests.cs | 15 +++++++ .../MinecraftJars.Tests.csproj | 1 + MinecraftJars.sln | 6 +++ MinecraftJars/IMinecraftJar.cs | 37 ++++++++++++++++ README.md | 10 ++++- 10 files changed, 167 insertions(+), 6 deletions(-) create mode 100644 MinecraftJars.Extension/MinecraftJars.Extension.DependencyInjection/MinecraftJars.Extension.DependencyInjection.csproj create mode 100644 MinecraftJars.Extension/MinecraftJars.Extension.DependencyInjection/README.md create mode 100644 MinecraftJars.Extension/MinecraftJars.Extension.DependencyInjection/ServiceCollectionExtensions.cs create mode 100644 MinecraftJars.Tests/DependencyInjectionTests.cs create mode 100644 MinecraftJars/IMinecraftJar.cs diff --git a/.github/workflows/build-and-publish.yml b/.github/workflows/build-and-publish.yml index 357764a..3a822f7 100644 --- a/.github/workflows/build-and-publish.yml +++ b/.github/workflows/build-and-publish.yml @@ -7,6 +7,7 @@ on: env: PROJECT_PATH: MinecraftJars/MinecraftJars.csproj + PROJECT_PATH_EXTENSION: MinecraftJars/MinecraftJars.csproj PACKAGE_OUTPUT_DIR: ${{ github.workspace }}/output NUGET_SOURCE_URL: "https://api.nuget.org/v3/index.json" @@ -24,17 +25,23 @@ jobs: dotnet-version: "7.0.x" - name: "Restore packages" - run: dotnet restore ${{ env.PROJECT_PATH }} + run: | + dotnet restore ${{ env.PROJECT_PATH }} + dotnet restore ${{ env.PROJECT_PATH_EXTENSION }} - name: "Build project" - run: dotnet build ${{ env.PROJECT_PATH }} --no-restore --configuration Release + run: | + dotnet build ${{ env.PROJECT_PATH }} --no-restore --configuration Release + dotnet build ${{ env.PROJECT_PATH_EXTENSION }} --no-restore --configuration Release - name: "Get version" id: version uses: battila7/get-version-action@v2 - name: "Pack project" - run: dotnet pack ${{ env.PROJECT_PATH }} --no-restore --configuration Release --p:PackageVersion=${{ steps.version.outputs.version-without-v }} --output ${{ env.PACKAGE_OUTPUT_DIR }} + run: | + dotnet pack ${{ env.PROJECT_PATH }} --no-restore --configuration Release --p:PackageVersion=${{ steps.version.outputs.version-without-v }} --output ${{ env.PACKAGE_OUTPUT_DIR }} + dotnet pack ${{ env.PROJECT_PATH_EXTENSION }} --no-restore --configuration Release --p:PackageVersion=${{ steps.version.outputs.version-without-v }} --output ${{ env.PACKAGE_OUTPUT_DIR }} - name: "Push package" run: dotnet nuget push ${{ env.PACKAGE_OUTPUT_DIR }}/*.nupkg --api-key ${{ secrets.NUGET_AUTH_TOKEN }} --source ${{ env.NUGET_SOURCE_URL }} diff --git a/CHANGELOG.md b/CHANGELOG.md index e2b3b42..a22ce71 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -3,10 +3,21 @@ All notable changes to this project will be documented in this file. ## [Unreleased] +## [1.4.0] - 2023-06-01 + +### Changed +- Renamed MinecraftJarManager to MinecraftJar + +### Added +- IMinecraftJar interface +- Extension for dependency injection +- Test case for dependency injection +- Automatic deployment of dependency injection injection to nuget.org + ## [1.3.2] - 2023-06-01 -### Fixed +### Added - Fabric version snapshot test missing ### Fixed diff --git a/MinecraftJars.Extension/MinecraftJars.Extension.DependencyInjection/MinecraftJars.Extension.DependencyInjection.csproj b/MinecraftJars.Extension/MinecraftJars.Extension.DependencyInjection/MinecraftJars.Extension.DependencyInjection.csproj new file mode 100644 index 0000000..be3f4ad --- /dev/null +++ b/MinecraftJars.Extension/MinecraftJars.Extension.DependencyInjection/MinecraftJars.Extension.DependencyInjection.csproj @@ -0,0 +1,42 @@ + + + + net7.0 + enable + enable + MinecraftJars.NET.Extensions.DependencyInjection + Patrick Weiss + MinecraftJars.NET.Extensions.DependencyInjection + MinecraftJars.NET Dependency Injection Extension + https://github.com/tekgator/MinecraftJars.NET + MinecraftJarsNET-Logo-128px.png + README.md + https://github.com/tekgator/MinecraftJars.NET + git + LICENSE + Dependency injection extension for MinecraftJars.NET + @Patrick Weiss 2023 + minecraftjars;minecraftjars.net;dependency injection;di + + + + + + + + + + + + + + True + \ + + + True + \ + + + + diff --git a/MinecraftJars.Extension/MinecraftJars.Extension.DependencyInjection/README.md b/MinecraftJars.Extension/MinecraftJars.Extension.DependencyInjection/README.md new file mode 100644 index 0000000..a1f7661 --- /dev/null +++ b/MinecraftJars.Extension/MinecraftJars.Extension.DependencyInjection/README.md @@ -0,0 +1,18 @@ +![MinecraftJars.NET dependency injection extensions](../../Resources/MinecraftJarsNET-Logo-64px.png "MinecraftJars.NET dependency injection extensions") +MinecraftJars.NET dependency injection extensions +====== + +## Installing + +Multiple options are available to install within your project: + +1. Install, using the [Nuget Gallery](https://www.nuget.org/packages/MinecraftJars.NET.Extensions.DependencyInjection) + +2. Install using the Package Manager Console: + ```ps + Install-Package MinecraftJars.NET.Extensions.DependencyInjection + ``` +3. Install using .NET CLI + ```cmd + dotnet add package MinecraftJars.NET.Extensions.DependencyInjection + ``` \ No newline at end of file diff --git a/MinecraftJars.Extension/MinecraftJars.Extension.DependencyInjection/ServiceCollectionExtensions.cs b/MinecraftJars.Extension/MinecraftJars.Extension.DependencyInjection/ServiceCollectionExtensions.cs new file mode 100644 index 0000000..2a9726d --- /dev/null +++ b/MinecraftJars.Extension/MinecraftJars.Extension.DependencyInjection/ServiceCollectionExtensions.cs @@ -0,0 +1,18 @@ +using Microsoft.Extensions.DependencyInjection; +using MinecraftJars.Core.Providers; + +namespace MinecraftJars.Extension.DependencyInjection; + +public static class ServiceCollectionExtensions +{ + public static IServiceCollection AddMinecraftJar(this IServiceCollection services) + { + services.AddHttpClient(); + services.AddScoped(sp => new MinecraftJar(new ProviderOptions + { + HttpClientFactory = sp.GetRequiredService() + })); + + return services; + } +} \ No newline at end of file diff --git a/MinecraftJars.Tests/DependencyInjectionTests.cs b/MinecraftJars.Tests/DependencyInjectionTests.cs new file mode 100644 index 0000000..2ff2ec0 --- /dev/null +++ b/MinecraftJars.Tests/DependencyInjectionTests.cs @@ -0,0 +1,15 @@ +using Microsoft.Extensions.DependencyInjection; +using MinecraftJars.Extension.DependencyInjection; + +namespace MinecraftJars.Tests; + +[TestFixture, Order(5)] +public class DependencyInjectionTests +{ + [Test] + public void DependencyInjection_Success() + { + using var serviceProvider = new ServiceCollection().AddMinecraftJar().BuildServiceProvider(); + Assert.That(serviceProvider.GetService(), Is.Not.Null); + } +} \ No newline at end of file diff --git a/MinecraftJars.Tests/MinecraftJars.Tests.csproj b/MinecraftJars.Tests/MinecraftJars.Tests.csproj index fd2f453..7363fc8 100644 --- a/MinecraftJars.Tests/MinecraftJars.Tests.csproj +++ b/MinecraftJars.Tests/MinecraftJars.Tests.csproj @@ -19,6 +19,7 @@ + diff --git a/MinecraftJars.sln b/MinecraftJars.sln index 86c1582..3368b20 100644 --- a/MinecraftJars.sln +++ b/MinecraftJars.sln @@ -22,6 +22,8 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "MinecraftJars.Plugin.Pocket EndProject Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "MinecraftJars.Plugin.Fabric", "MinecraftJars.Plugin\MinecraftJars.Plugin.Fabric\MinecraftJars.Plugin.Fabric.csproj", "{032DAEF4-810E-44B4-A8E0-4A0039B1D42E}" EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "MinecraftJars.Extension.DependencyInjection", "MinecraftJars.Extension\MinecraftJars.Extension.DependencyInjection\MinecraftJars.Extension.DependencyInjection.csproj", "{A9F4324F-BABF-4EE1-9856-B169368BA9EE}" +EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Any CPU = Debug|Any CPU @@ -72,5 +74,9 @@ Global {032DAEF4-810E-44B4-A8E0-4A0039B1D42E}.Debug|Any CPU.Build.0 = Debug|Any CPU {032DAEF4-810E-44B4-A8E0-4A0039B1D42E}.Release|Any CPU.ActiveCfg = Release|Any CPU {032DAEF4-810E-44B4-A8E0-4A0039B1D42E}.Release|Any CPU.Build.0 = Release|Any CPU + {A9F4324F-BABF-4EE1-9856-B169368BA9EE}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {A9F4324F-BABF-4EE1-9856-B169368BA9EE}.Debug|Any CPU.Build.0 = Debug|Any CPU + {A9F4324F-BABF-4EE1-9856-B169368BA9EE}.Release|Any CPU.ActiveCfg = Release|Any CPU + {A9F4324F-BABF-4EE1-9856-B169368BA9EE}.Release|Any CPU.Build.0 = Release|Any CPU EndGlobalSection EndGlobal diff --git a/MinecraftJars/IMinecraftJar.cs b/MinecraftJars/IMinecraftJar.cs new file mode 100644 index 0000000..0460c29 --- /dev/null +++ b/MinecraftJars/IMinecraftJar.cs @@ -0,0 +1,37 @@ +using MinecraftJars.Core.Projects; +using MinecraftJars.Core.Providers; + +namespace MinecraftJars; + +public interface IMinecraftJar +{ + /// + /// Return a list of all providers (plugins) + /// + IEnumerable GetProviders(); + + /// + /// Return a list of all providers offering a certain project group + /// + IEnumerable GetProviders(Group group); + + /// + /// Return a specific provider + /// + IMinecraftProvider GetProvider(string provider); + + /// + /// Return the provider for the provided Project + /// + IMinecraftProvider GetProvider(IMinecraftProject project); + + /// + /// Return a list of all projects (e.g. Vanilla, Spigot, etc.) + /// + IEnumerable GetProjects(); + + /// + /// Return a list of all projects for a certain type (e.g. all proxies) + /// + IEnumerable GetProjects(Group group); +} \ No newline at end of file diff --git a/README.md b/README.md index 226e2f9..21ede9b 100644 --- a/README.md +++ b/README.md @@ -66,14 +66,14 @@ Multiple options are available to install within your project: ## Usage -MinecraftJars.NET comes with a `MinecraftJarManager` class which has to be instantiated, optionally `ProviderOptions` can be supplied. +MinecraftJars.NET comes with a `MinecraftJar` class which has to be instantiated, optionally `ProviderOptions` can be supplied. Each Plugin provides an interface instance for the provider `IMinecraftProvider` as well an interface instance for `IEnumerable` with it's versions `IEnumerable`. Since getting the actual download link mostly involves another API query it is accessible via the `IMinecraftVersion.GetDownload()` method. ```CSharp using MinecraftJars; -var jarManager = new MinecraftJarManager(); +var jarManager = new MinecraftJar(); foreach (var provider in jarManager.GetProviders()) { @@ -116,6 +116,12 @@ As an example with the Paper Minecraft experience following values can be expect - Not all providers will fill all properties in each interface instance. Further information are provided in the README.md of each plugin. +## Dependency Injection + +An extensions package is available for [Dependency Injection](MinecraftJars.Extension/MinecraftJars.Extension.DependencyInjection). +Look up the project but it is as easy as installing it and adding MinecraftJar.NET to the DI. + + ## Demo application Have a look at the [Console Demo](MinecraftJars.Demo/MinecraftJars.Demo.Console) within the repository. From d55c8ce72870b11184355a1f2322051347019632 Mon Sep 17 00:00:00 2001 From: tekgator Date: Sat, 3 Jun 2023 09:19:54 +1000 Subject: [PATCH 3/4] Add usage instructions --- .../README.md | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) diff --git a/MinecraftJars.Extension/MinecraftJars.Extension.DependencyInjection/README.md b/MinecraftJars.Extension/MinecraftJars.Extension.DependencyInjection/README.md index a1f7661..2d2ef51 100644 --- a/MinecraftJars.Extension/MinecraftJars.Extension.DependencyInjection/README.md +++ b/MinecraftJars.Extension/MinecraftJars.Extension.DependencyInjection/README.md @@ -15,4 +15,21 @@ Multiple options are available to install within your project: 3. Install using .NET CLI ```cmd dotnet add package MinecraftJars.NET.Extensions.DependencyInjection - ``` \ No newline at end of file + ``` + +## Usage + +As simple as + +```CSharp + +// Registering DI +services.AddMinecraftJar(); + +// Injecting e.g. via service provider +var minecraftJar = serviceProvider.GetRequiredService() + +// Usage +var providers = minecraftJar.GetProviders(); + +``` \ No newline at end of file From f49b53f0d9b943218d61f074e5d464f9251c6753 Mon Sep 17 00:00:00 2001 From: tekgator Date: Sat, 3 Jun 2023 09:20:05 +1000 Subject: [PATCH 4/4] correct variable name --- README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 21ede9b..78855dd 100644 --- a/README.md +++ b/README.md @@ -73,9 +73,9 @@ Since getting the actual download link mostly involves another API query it is a ```CSharp using MinecraftJars; -var jarManager = new MinecraftJar(); +var minecraftJar = new MinecraftJar(); -foreach (var provider in jarManager.GetProviders()) +foreach (var provider in minecraftJar.GetProviders()) { Console.WriteLine($"{provider}");