fix: load Matrix42 services for web api

This commit is contained in:
Meik
2026-06-26 17:41:51 +02:00
parent 36181e6462
commit f1c6413280
3 changed files with 13 additions and 59 deletions

View File

@@ -9,7 +9,6 @@ using System.Threading.Tasks;
using Matrix42.Common;
using Matrix42.Contracts.ServiceManagement.ServiceContracts;
using Matrix42.Hosting.Contracts;
using Matrix42.Pandora.Contracts;
using Matrix42.Services.Description.Contracts;
using Matrix42.WebApi.Contracts;
@@ -32,9 +31,9 @@ namespace C4IT.F4SD
public static F4SDM42WebApiController defaultInstance;
//private readonly IIncidentService _incidentService;
internal readonly GlobalConfigurationProvider _globalConfigurationProvider;
public readonly IJournalService _journalService;
//public readonly IObjectService _objectService;
//public readonly IFragmentService _fragmentService;
public readonly IJournalService _journalService;
internal readonly IEntityDataService _entityDataService;
internal readonly IPandoraUserProfile _userProfile;
@@ -43,60 +42,15 @@ namespace C4IT.F4SD
public string BaseUrl => Request?.RequestUri == null ? string.Empty : $"{Request.RequestUri.Scheme}://{Request.RequestUri.Host}";
public string EndpointBaseUrl => $"{BaseUrl}/m42Services/api/c4itf4sdwebapi";
public F4SDM42WebApiController(IDependencyResolver resolver)
public F4SDM42WebApiController(IEntityDataService entityDataService, IJournalService journalService, IPandoraUserProfile userProfile)
{
defaultInstance = this;
_globalConfigurationProvider = GlobalConfigurationProvider.Instance;
_f4stHelperService = new F4SDHelperService();
EnsureInitialized();
_entityDataService = ResolveOptional<IEntityDataService>(resolver);
_journalService = ResolveOptional<IJournalService>(resolver);
_userProfile = ResolveOptional<IPandoraUserProfile>(resolver);
}
private static T ResolveOptional<T>(IDependencyResolver resolver) where T : class
{
if (resolver == null)
return null;
try
{
if (!resolver.IsRegistered<T>())
return null;
}
catch
{
}
try
{
return resolver.TryGet<T>();
}
catch (Exception ex)
{
LogOptionalDependencyFailure(typeof(T), ex);
return null;
}
}
private static void LogOptionalDependencyFailure(Type dependencyType, Exception exception)
{
try
{
LogEntry($"Matrix42 dependency '{dependencyType.FullName}' could not be resolved.", LogLevels.Warning);
LogException(exception);
}
catch
{
}
}
private HttpResponseMessage CreateMissingDependencyResponse(Type dependencyType)
{
return HttpResponseExtensions.CreateResponse(
Request,
HttpStatusCode.ServiceUnavailable,
$"Matrix42 dependency '{dependencyType.FullName}' is not registered for this extension context.");
_entityDataService = entityDataService ?? throw new ArgumentNullException(nameof(entityDataService));
_journalService = journalService ?? throw new ArgumentNullException(nameof(journalService));
_userProfile = userProfile ?? throw new ArgumentNullException(nameof(userProfile));
}
private static readonly object initLock = new object();
@@ -323,9 +277,6 @@ namespace C4IT.F4SD
public async Task<HttpResponseMessage> getPickup(string name, [FromUri] EntityEnumerationVisibilityMode mode = EntityEnumerationVisibilityMode.None, [FromUri] Int32 group = -1)
{
await Task.Delay(0);
if (_entityDataService == null)
return CreateMissingDependencyResponse(typeof(IEntityDataService));
EntityEnumeration enumerationTemp = _entityDataService.GetEnumeration(name, mode);
var vals = enumerationTemp.Values;
@@ -352,9 +303,6 @@ namespace C4IT.F4SD
[Route("getMyRoleMemberships"), HttpGet]
public async Task<HttpResponseMessage> getMyRoleMemberships()
{
if (_userProfile == null)
return CreateMissingDependencyResponse(typeof(IPandoraUserProfile));
var User = _userProfile.GetInteractiveUserInfo();
var filter = AsqlHelper.BuildInCondition("ID", new Guid[] { User.Id });
return HttpResponseExtensions.CreateResponse(Request, HttpStatusCode.OK, await _f4stHelperService.UserPermissionsInfo(filter));