Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
implement service resolver for script plugins
- Loading branch information
Showing
6 changed files
with
56 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
using SharedLibraryCore.Interfaces; | ||
using System; | ||
using System.Linq; | ||
|
||
namespace IW4MAdmin.Application.Misc | ||
{ | ||
/// <summary> | ||
/// implementation of IScriptPluginServiceResolver | ||
/// </summary> | ||
public class ScriptPluginServiceResolver : IScriptPluginServiceResolver | ||
{ | ||
private readonly IServiceProvider _serviceProvider; | ||
|
||
public ScriptPluginServiceResolver(IServiceProvider serviceProvider) | ||
{ | ||
_serviceProvider = serviceProvider; | ||
} | ||
|
||
public object ResolveService(string serviceName) | ||
{ | ||
var serviceType = typeof(IScriptPluginServiceResolver).Assembly.GetTypes().FirstOrDefault(_type => _type.Name == serviceName); | ||
|
||
if (serviceType == null) | ||
{ | ||
throw new InvalidOperationException($"No service type '{serviceName}' defined in IW4MAdmin assembly"); | ||
} | ||
|
||
return _serviceProvider.GetService(serviceType); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
10 changes: 10 additions & 0 deletions
10
SharedLibraryCore/Interfaces/IScriptPluginServiceResolver.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
namespace SharedLibraryCore.Interfaces | ||
{ | ||
/// <summary> | ||
/// interface used to dynamically resolve services by string name | ||
/// </summary> | ||
public interface IScriptPluginServiceResolver | ||
{ | ||
object ResolveService(string serviceName); | ||
} | ||
} |