-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathServiceCommand.cs
More file actions
31 lines (26 loc) · 1 KB
/
ServiceCommand.cs
File metadata and controls
31 lines (26 loc) · 1 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
namespace CommandMiddleware
{
using System;
using System.Reflection;
internal class ServiceCommand : Command
{
private readonly Type serviceType;
public ServiceCommand(string name, Type serviceType, MethodInfo methodInfo, string? prefix = null)
: base(
name,
allowAnonymous: methodInfo.IsDefined(typeof(AllowAnonymousAttribute), false) || serviceType.IsDefined(typeof(AllowAnonymousAttribute), false),
rawResult: methodInfo.IsDefined(typeof(RawResultAttribute), false))
{
this.MethodInfo = methodInfo;
this.serviceType = serviceType;
this.Prefix = prefix;
}
public string? Prefix { get; }
protected override MethodInfo MethodInfo { get; }
public override object? Invoke(IServiceProvider container, object[] args)
{
var service = container.GetService(serviceType);
return MethodInfo.Invoke(service, args);
}
}
}