Skip to content

Commit

Permalink
Add dependency injection package
Browse files Browse the repository at this point in the history
  • Loading branch information
tekgator committed Jun 2, 2023
1 parent 6a7b7a9 commit e70f23f
Show file tree
Hide file tree
Showing 10 changed files with 167 additions and 6 deletions.
13 changes: 10 additions & 3 deletions .github/workflows/build-and-publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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"

Expand All @@ -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 }}
Expand Down
13 changes: 12 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>net7.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
<PackageId>MinecraftJars.NET.Extensions.DependencyInjection</PackageId>
<Authors>Patrick Weiss</Authors>
<Product>MinecraftJars.NET.Extensions.DependencyInjection</Product>
<Title>MinecraftJars.NET Dependency Injection Extension</Title>
<PackageProjectUrl>https://github.com/tekgator/MinecraftJars.NET</PackageProjectUrl>
<PackageIcon>MinecraftJarsNET-Logo-128px.png</PackageIcon>
<PackageReadmeFile>README.md</PackageReadmeFile>
<RepositoryUrl>https://github.com/tekgator/MinecraftJars.NET</RepositoryUrl>
<RepositoryType>git</RepositoryType>
<PackageLicenseFile>LICENSE</PackageLicenseFile>
<Description>Dependency injection extension for MinecraftJars.NET</Description>
<Copyright>@Patrick Weiss 2023</Copyright>
<PackageTags>minecraftjars;minecraftjars.net;dependency injection;di</PackageTags>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Microsoft.Extensions.DependencyInjection.Abstractions" Version="7.0.0" />
</ItemGroup>

<ItemGroup>
<ProjectReference Include="..\..\MinecraftJars.Core\MinecraftJars.Core.csproj" />
<ProjectReference Include="..\..\MinecraftJars\MinecraftJars.csproj" />
</ItemGroup>

<ItemGroup>
<None Include="..\..\LICENSE">
<Pack>True</Pack>
<PackagePath>\</PackagePath>
</None>
<None Include="..\..\Resources\MinecraftJarsNET-Logo-128px.png">
<Pack>True</Pack>
<PackagePath>\</PackagePath>
</None>
</ItemGroup>

</Project>
Original file line number Diff line number Diff line change
@@ -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
```
Original file line number Diff line number Diff line change
@@ -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<IMinecraftJar, MinecraftJar>(sp => new MinecraftJar(new ProviderOptions
{
HttpClientFactory = sp.GetRequiredService<IHttpClientFactory>()
}));

return services;
}
}
15 changes: 15 additions & 0 deletions MinecraftJars.Tests/DependencyInjectionTests.cs
Original file line number Diff line number Diff line change
@@ -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<IMinecraftJar>(), Is.Not.Null);
}
}
1 change: 1 addition & 0 deletions MinecraftJars.Tests/MinecraftJars.Tests.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@

<ItemGroup>
<ProjectReference Include="..\MinecraftJars.Core\MinecraftJars.Core.csproj" />
<ProjectReference Include="..\MinecraftJars.Extension\MinecraftJars.Extension.DependencyInjection\MinecraftJars.Extension.DependencyInjection.csproj" />
<ProjectReference Include="..\MinecraftJars.Plugin\MinecraftJars.Plugin.Fabric\MinecraftJars.Plugin.Fabric.csproj" />
<ProjectReference Include="..\MinecraftJars.Plugin\MinecraftJars.Plugin.Mohist\MinecraftJars.Plugin.Mohist.csproj" />
<ProjectReference Include="..\MinecraftJars.Plugin\MinecraftJars.Plugin.Mojang\MinecraftJars.Plugin.Mojang.csproj" />
Expand Down
6 changes: 6 additions & 0 deletions MinecraftJars.sln
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
37 changes: 37 additions & 0 deletions MinecraftJars/IMinecraftJar.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
using MinecraftJars.Core.Projects;
using MinecraftJars.Core.Providers;

namespace MinecraftJars;

public interface IMinecraftJar
{
/// <summary>
/// Return a list of all providers (plugins)
/// </summary>
IEnumerable<IMinecraftProvider> GetProviders();

/// <summary>
/// Return a list of all providers offering a certain project group
/// </summary>
IEnumerable<IMinecraftProvider> GetProviders(Group group);

/// <summary>
/// Return a specific provider
/// </summary>
IMinecraftProvider GetProvider(string provider);

/// <summary>
/// Return the provider for the provided Project
/// </summary>
IMinecraftProvider GetProvider(IMinecraftProject project);

/// <summary>
/// Return a list of all projects (e.g. Vanilla, Spigot, etc.)
/// </summary>
IEnumerable<IMinecraftProject> GetProjects();

/// <summary>
/// Return a list of all projects for a certain type (e.g. all proxies)
/// </summary>
IEnumerable<IMinecraftProject> GetProjects(Group group);
}
10 changes: 8 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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<IMinecraftProject>` with it's versions `IEnumerable<IMinecraftVersion>`.
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())
{
Expand Down Expand Up @@ -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.
Expand Down

0 comments on commit e70f23f

Please sign in to comment.