From d080aa3b658fa07faf9e2ce43a5f50274e386347 Mon Sep 17 00:00:00 2001 From: Chase Hanson Date: Fri, 25 Oct 2024 22:24:00 -0700 Subject: [PATCH] Simplifiy --- .../Configs/Lti13PlatformCoreConfig.cs | 1 - NP.Lti13Platform.Core/Lti13PlatformBuilder.cs | 42 ++++++------------- NP.Lti13Platform.Core/README.md | 3 +- NP.Lti13Platform.Core/Startup.cs | 12 +++--- NP.Lti13Platform.DeepLinking/Startup.cs | 12 +++--- 5 files changed, 25 insertions(+), 45 deletions(-) diff --git a/NP.Lti13Platform.Core/Configs/Lti13PlatformCoreConfig.cs b/NP.Lti13Platform.Core/Configs/Lti13PlatformCoreConfig.cs index d254e07..3e79a97 100644 --- a/NP.Lti13Platform.Core/Configs/Lti13PlatformCoreConfig.cs +++ b/NP.Lti13Platform.Core/Configs/Lti13PlatformCoreConfig.cs @@ -3,7 +3,6 @@ public class Lti13PlatformTokenConfig { private const string INVALID_ISSUER = "Issuer must follow the guidelines in the LTI 1.3 security spec. https://www.imsglobal.org/spec/security/v1p0/#dfn-issuer-identifier"; - private const string INVALID_TOKEN_AUDIENCE = "Token Audience must follow the guidelines in the LTI 1.3 security spec. https://www.imsglobal.org/spec/security/v1p0/#dfn-issuer-identifier"; private string _issuer = string.Empty; /// diff --git a/NP.Lti13Platform.Core/Lti13PlatformBuilder.cs b/NP.Lti13Platform.Core/Lti13PlatformBuilder.cs index 3582b07..b83acbb 100644 --- a/NP.Lti13Platform.Core/Lti13PlatformBuilder.cs +++ b/NP.Lti13Platform.Core/Lti13PlatformBuilder.cs @@ -50,7 +50,18 @@ public Lti13PlatformBuilder ExtendLti13Message(string? messageType = null) { if (!MessageTypes.TryGetValue(messageType, out var mt)) { - AddMessageHandler(messageType); + MessageTypes.TryAdd(messageType, new MessageType(messageType, [.. GlobalInterfaces])); + + foreach (var globalPopulator in GlobalPopulators) + { + services.AddKeyedTransient(typeof(Populator), messageType, globalPopulator); + } + + services.AddKeyedTransient(messageType, (sp, obj) => + { + return (LtiMessage)Activator.CreateInstance(LtiMessageTypes[messageType])!; + }); + mt = MessageTypes[messageType]; } @@ -61,23 +72,6 @@ public Lti13PlatformBuilder ExtendLti13Message(string? messageType = null) return this; } - public Lti13PlatformMessageBuilder AddMessageHandler(string messageType) - { - MessageTypes.TryAdd(messageType, new MessageType(messageType, [.. GlobalInterfaces])); - - foreach (var globalPopulator in GlobalPopulators) - { - services.AddKeyedTransient(typeof(Populator), messageType, globalPopulator); - } - - services.AddKeyedTransient(messageType, (sp, obj) => - { - return (LtiMessage)Activator.CreateInstance(LtiMessageTypes[messageType])!; - }); - - return new Lti13PlatformMessageBuilder(services, messageType); - } - internal static void CreateTypes() { if (LtiMessageTypes.Count == 0) @@ -93,16 +87,4 @@ internal static void CreateTypes() public IServiceCollection Services => services; } - - public class Lti13PlatformMessageBuilder(IServiceCollection baseCollection, string messageType) : Lti13PlatformBuilder(baseCollection) - { - public Lti13PlatformMessageBuilder Extend() - where T : class - where U : Populator - { - base.ExtendLti13Message(messageType); - - return this; - } - } } diff --git a/NP.Lti13Platform.Core/README.md b/NP.Lti13Platform.Core/README.md index b561a91..e686922 100644 --- a/NP.Lti13Platform.Core/README.md +++ b/NP.Lti13Platform.Core/README.md @@ -199,7 +199,7 @@ builder.Services ## Custom Messgage Types -LTI allows for message types not defined officially in any spec. A custom message type can be defined between tools and platforms. This is handled here by creating a new message handler and extending it with the interfaces and populators it needs. +LTI allows for message types not defined officially in any spec. A custom message type can be defined between tools and platforms. This is handled here by extending a message type name it with the interfaces and populators it needs. ```csharp interface ICustomMessage @@ -223,7 +223,6 @@ class CustomPopulator: Populator builder.Services .AddLti13PlatformCore() - .AddMessageHandler("CustomMessage") .ExtendLti13Message("CustomMessage"); ``` diff --git a/NP.Lti13Platform.Core/Startup.cs b/NP.Lti13Platform.Core/Startup.cs index 986b23e..0e2c66a 100644 --- a/NP.Lti13Platform.Core/Startup.cs +++ b/NP.Lti13Platform.Core/Startup.cs @@ -50,12 +50,12 @@ public static Lti13PlatformBuilder AddLti13PlatformCore(this IServiceCollection builder.Services.AddTransient(); - builder.AddMessageHandler(Lti13MessageType.LtiResourceLinkRequest) - .Extend() - .Extend() - .Extend() - .Extend() - .Extend(); + builder + .ExtendLti13Message(Lti13MessageType.LtiResourceLinkRequest) + .ExtendLti13Message(Lti13MessageType.LtiResourceLinkRequest) + .ExtendLti13Message(Lti13MessageType.LtiResourceLinkRequest) + .ExtendLti13Message(Lti13MessageType.LtiResourceLinkRequest) + .ExtendLti13Message(Lti13MessageType.LtiResourceLinkRequest); builder.Services.AddAuthentication() .AddScheme(LtiServicesAuthHandler.SchemeName, null); diff --git a/NP.Lti13Platform.DeepLinking/Startup.cs b/NP.Lti13Platform.DeepLinking/Startup.cs index 427fbd5..7918bae 100644 --- a/NP.Lti13Platform.DeepLinking/Startup.cs +++ b/NP.Lti13Platform.DeepLinking/Startup.cs @@ -22,12 +22,12 @@ public static class Startup { public static Lti13PlatformBuilder AddLti13PlatformDeepLinking(this Lti13PlatformBuilder builder) { - builder.AddMessageHandler(Lti13MessageType.LtiDeepLinkingRequest) - .Extend() - .Extend() - .Extend() - .Extend() - .Extend(); + builder + .ExtendLti13Message(Lti13MessageType.LtiDeepLinkingRequest) + .ExtendLti13Message(Lti13MessageType.LtiDeepLinkingRequest) + .ExtendLti13Message(Lti13MessageType.LtiDeepLinkingRequest) + .ExtendLti13Message(Lti13MessageType.LtiDeepLinkingRequest) + .ExtendLti13Message(Lti13MessageType.LtiDeepLinkingRequest); return builder; }