From 61298047ca502e0f7c0cce3f9cfa61c4047fad68 Mon Sep 17 00:00:00 2001 From: Mike Dickson Date: Thu, 29 Feb 2024 11:06:35 -0500 Subject: [PATCH] Use DI to load the service associated with the handler using a tagname. This used to be done low level using regular assembly loading but you dont get the DI behaviour and dependency tracking that way. --- .vscode/launch.json | 43 ------- Source/OpenSim.Data.Model/.gitignore | 1 + Source/OpenSim.Server.Base/ServerUtils.cs | 115 ------------------ .../OpenSim.Server.GridServer/GridService.cs | 4 +- .../AuthenticationServerConnector.cs | 27 ++-- .../Authentication/OpenIdServerConnector.cs | 27 ++-- .../AuthorizationServerConnector.cs | 23 ++-- .../Avatar/AvatarServerConnector.cs | 23 ++-- .../BakedTextures/XBakesHandler.cs | 24 ++-- .../Base/IServiceConnector.cs | 6 +- .../Estate/EstateDataRobustConnector.cs | 27 ++-- .../Freeswitch/FreeswitchServerConnector.cs | 22 ++-- .../Friends/FriendServerConnector.cs | 26 ++-- .../Grid/GridServerConnector.cs | 23 ++-- .../GridUser/GridUserServerConnector.cs | 27 ++-- .../Hypergrid/GatekeeperServerConnector.cs | 27 ++-- .../Hypergrid/HGFriendServerConnector.cs | 29 +++-- .../InstantMessageServerConnector.cs | 34 +++--- .../Hypergrid/UserAgentServerConnector.cs | 32 ++--- .../Inventory/InventoryServerInConnector.cs | 32 ++--- .../Inventory/XInventoryInConnector.cs | 33 ++--- .../Login/LLLoginServiceInConnector.cs | 53 ++++---- .../Map/MapAddServerConnector.cs | 33 +++-- .../Map/MapGetServerConnector.cs | 25 ++-- .../Map/MapRemoveServerConnector.cs | 30 +++-- .../MuteList/MuteListServerConnector.cs | 24 ++-- .../Presence/PresenceServerConnector.cs | 24 ++-- .../Profiles/UserProfilesConnector.cs | 31 ++--- .../UserAccountServerConnector.cs | 24 ++-- .../UserAlias/UserAliasServiceConnector.cs | 23 ++-- 30 files changed, 397 insertions(+), 475 deletions(-) delete mode 100644 .vscode/launch.json create mode 100644 Source/OpenSim.Data.Model/.gitignore diff --git a/.vscode/launch.json b/.vscode/launch.json deleted file mode 100644 index ed78c290d57..00000000000 --- a/.vscode/launch.json +++ /dev/null @@ -1,43 +0,0 @@ -{ - // Use IntelliSense to learn about possible attributes. - // Hover to view descriptions of existing attributes. - // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387 - "version": "0.2.0", - "configurations": [ - { - "name": ".NET Core Attach", - "type": "coreclr", - "request": "attach" - }, - { - "name": "C#: OpenSim.Server.MoneyServer Debug", - "type": "coreclr", - "request": "launch", - "program": "${workspaceFolder}/Source/OpenSim.Server.MoneyServer/bin/Debug/net8.0/OpenSim.Server.MoneyServer.dll", - "args": ["--console","local","--inifile","${workspaceFolder}/../../Config/MoneyServer.ini"], - "cwd": "${workspaceFolder}", - "stopAtEntry": true, - "console": "integratedTerminal" - }, - { - "name": "C#: OpenSim.Server.GridServer Debug", - "type": "coreclr", - "request": "launch", - "program": "${workspaceFolder}/Source/OpenSim.Server.GridServer/bin/Debug/net8.0/OpenSim.Server.GridServer.dll", - "args": ["--console","local","--inifile","${workspaceFolder}/../../Config/Robust.Grid.ini"], - "cwd": "${workspaceFolder}", - "stopAtEntry": true, - "console": "integratedTerminal" - }, - { - "name": "C#: OpenSim.Server.RegionServer Debug", - "type": "coreclr", - "request": "launch", - "program": "${workspaceFolder}/Source/OpenSim.Server.RegionServer/bin/Debug/net8.0/OpenSim.Server.RegionServer.dll", - "args": ["--console","local","--inifile","${workspaceFolder}/../../Config/OpenSim.ini.ini"], - "cwd": "${workspaceFolder}", - "stopAtEntry": true, - "console": "integratedTerminal" - }, - ] -} \ No newline at end of file diff --git a/Source/OpenSim.Data.Model/.gitignore b/Source/OpenSim.Data.Model/.gitignore new file mode 100644 index 00000000000..7089070cc75 --- /dev/null +++ b/Source/OpenSim.Data.Model/.gitignore @@ -0,0 +1 @@ +scaffold.sh diff --git a/Source/OpenSim.Server.Base/ServerUtils.cs b/Source/OpenSim.Server.Base/ServerUtils.cs index 324a26775c1..5ebd986df78 100644 --- a/Source/OpenSim.Server.Base/ServerUtils.cs +++ b/Source/OpenSim.Server.Base/ServerUtils.cs @@ -99,121 +99,6 @@ public static string ParseDllName(string service) return (dllName); } - /// - /// Load a plugin from a dll with the given class or interface - /// - /// - /// The arguments which control which constructor is invoked on the plugin - /// - public static T LoadPlugin(string dllName, Object[] args) where T : class - { - // This is good to debug configuration problems - //if (dllName.Length == 0) - // Util.PrintCallStack(); - - string className = String.Empty; - - // The path for a dynamic plugin will contain ":" on Windows - string[] parts = dllName.Split(new char[] { ':' }); - - if (parts.Length < 3) - { - // Linux. There will be ':' but the one we're looking for - dllName = parts[0]; - if (parts.Length > 1) - className = parts[1]; - } - else - { - // This is Windows - we must replace the ":" in the path - dllName = String.Format("{0}:{1}", parts[0], parts[1]); - if (parts.Length > 2) - className = parts[2]; - } - - // Handle extra string arguments in a more generic way - if (dllName.Contains("@")) - { - string[] dllNameParts = dllName.Split(new char[] { '@' }); - dllName = dllNameParts[dllNameParts.Length - 1]; - List argList = new List(args); - for (int i = 0; i < dllNameParts.Length - 1; ++i) - argList.Add(dllNameParts[i]); - - args = argList.ToArray(); - } - - return LoadPlugin(dllName, className, args); - } - - /// - /// Load a plugin from a dll with the given class or interface - /// - /// - /// - /// The arguments which control which constructor is invoked on the plugin - /// - public static T LoadPlugin(string dllName, string className, Object[] args) where T : class - { - string interfaceName = typeof(T).ToString(); - - try - { - Assembly pluginAssembly = Assembly.LoadFrom(dllName); - - foreach (Type pluginType in pluginAssembly.GetTypes()) - { - if (pluginType.IsPublic) - { - if (className != String.Empty - && pluginType.ToString() != pluginType.Namespace + "." + className) - continue; - - Type typeInterface = pluginType.GetInterface(interfaceName); - - if (typeInterface != null) - { - T plug = null; - try - { - plug = (T)Activator.CreateInstance(pluginType, - args); - } - catch (Exception e) - { - if (!(e is System.MissingMethodException)) - { - m_log.Error(string.Format("[SERVER UTILS]: Error loading plugin {0} from {1}. Exception: {2}", - interfaceName, - dllName, - e.InnerException == null ? e.Message : e.InnerException.Message), - e); - } - m_log.ErrorFormat("[SERVER UTILS]: Error loading plugin {0}: {1} args.Length {2}", dllName, e.Message, args.Length); - return null; - } - - return plug; - } - } - } - - return null; - } - catch (ReflectionTypeLoadException rtle) - { - m_log.Error(string.Format("[SERVER UTILS]: Error loading plugin from {0}:\n{1}", dllName, - String.Join("\n", Array.ConvertAll(rtle.LoaderExceptions, e => e.ToString()))), - rtle); - return null; - } - catch (Exception e) - { - m_log.Error(string.Format("[SERVER UTILS]: Error loading plugin from {0}", dllName), e); - return null; - } - } - public static Dictionary ParseQueryString(string query) { string[] terms = query.Split(new char[] { '&' }); diff --git a/Source/OpenSim.Server.GridServer/GridService.cs b/Source/OpenSim.Server.GridServer/GridService.cs index 8f984184ec5..a4bb9dc1642 100644 --- a/Source/OpenSim.Server.GridServer/GridService.cs +++ b/Source/OpenSim.Server.GridServer/GridService.cs @@ -12,8 +12,6 @@ public sealed class GridService : IHostedService private readonly IConfiguration _configuration; private readonly GridServer _openSimServer; - private int m_res; - public GridService( IConfiguration configuration, ILogger logger, @@ -37,6 +35,8 @@ public Task StartAsync(CancellationToken stoppingToken) public Task StopAsync(CancellationToken stoppingToken) { + int m_res = 0; + _logger.LogInformation("{Service} is stopping.", nameof(Server.GridServer)); _openSimServer.Shutdown(m_res); diff --git a/Source/OpenSim.Server.Handlers/Authentication/AuthenticationServerConnector.cs b/Source/OpenSim.Server.Handlers/Authentication/AuthenticationServerConnector.cs index b1777374f56..b12a6f97ad7 100644 --- a/Source/OpenSim.Server.Handlers/Authentication/AuthenticationServerConnector.cs +++ b/Source/OpenSim.Server.Handlers/Authentication/AuthenticationServerConnector.cs @@ -25,6 +25,8 @@ * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ +using Autofac; + using OpenSim.Server.Base; using OpenSim.Services.Interfaces; using OpenSim.Framework.ServiceAuth; @@ -41,28 +43,30 @@ public class AuthenticationServiceConnector : IServiceConnector private IAuthenticationService m_AuthenticationService; private IHttpServer m_httpServer; + protected readonly IConfiguration m_configuration; + protected readonly ILogger m_logger; + protected readonly IComponentContext m_context; + public AuthenticationServiceConnector( IConfiguration configuraion, - ILogger logger + ILogger logger, + IComponentContext componentContext ) { - Config = configuraion; - Logger = logger; + m_configuration = configuraion; + m_logger = logger; + m_context = componentContext; } public string ConfigName => "AuthenticationService"; - public IConfiguration Config { get; private set; } - - public ILogger Logger { get; private set; } - public IHttpServer HttpServer => m_httpServer; public void Initialize(IHttpServer httpServer) { m_httpServer = httpServer; - var serverConfig = Config.GetSection(ConfigName); + var serverConfig = m_configuration.GetSection(ConfigName); if (serverConfig.Exists() is false) throw new Exception($"No section {ConfigName} in config file"); @@ -70,12 +74,11 @@ public void Initialize(IHttpServer httpServer) if (string.IsNullOrEmpty(authenticationService)) throw new Exception("No LocalServiceModule in config file"); - Object[] args = new Object[] { Config }; - m_AuthenticationService = ServerUtils.LoadPlugin(authenticationService, args); + m_AuthenticationService = m_context.ResolveNamed(authenticationService); - IServiceAuth auth = ServiceAuth.Create(Config, ConfigName); + IServiceAuth auth = ServiceAuth.Create(m_configuration, ConfigName); - HttpServer.AddStreamHandler(new AuthenticationServerPostHandler(m_AuthenticationService, Config, auth)); + HttpServer.AddStreamHandler(new AuthenticationServerPostHandler(m_AuthenticationService, m_configuration, auth)); } } } diff --git a/Source/OpenSim.Server.Handlers/Authentication/OpenIdServerConnector.cs b/Source/OpenSim.Server.Handlers/Authentication/OpenIdServerConnector.cs index b958e819c48..2d00706205c 100644 --- a/Source/OpenSim.Server.Handlers/Authentication/OpenIdServerConnector.cs +++ b/Source/OpenSim.Server.Handlers/Authentication/OpenIdServerConnector.cs @@ -32,6 +32,7 @@ using Microsoft.Extensions.Configuration; using Microsoft.Extensions.Logging; +using Autofac; namespace OpenSim.Server.Handlers.Authentication { @@ -40,26 +41,30 @@ public class OpenIdServerConnector : IServiceConnector private IAuthenticationService m_AuthenticationService; private IUserAccountService m_UserAccountService; + protected readonly IConfiguration m_configuration; + protected readonly ILogger m_logger; + protected readonly IComponentContext m_context; + + public OpenIdServerConnector( IConfiguration configuration, - ILogger logger + ILogger logger, + IComponentContext componentContext ) { - Config = configuration; - Logger = Logger; + m_configuration = configuration; + m_logger = logger; + m_context = componentContext; } public string ConfigName => "OpenIdService"; - public IConfiguration Config { get; private set; } - public ILogger Logger { get; private set; } public IHttpServer HttpServer { get; private set; } public void Initialize(IHttpServer httpServer) - { - HttpServer = httpServer; + { - var serverConfig = Config.GetSection(ConfigName); + var serverConfig = m_configuration.GetSection(ConfigName); if (serverConfig.Exists() is false) throw new Exception($"No section {ConfigName} in config file"); @@ -72,10 +77,8 @@ public void Initialize(IHttpServer httpServer) if (string.IsNullOrEmpty(userService)) throw new Exception("No UserAccountServiceModule in config file for OpenId authentication"); - Object[] args = new Object[] { Config }; - - m_AuthenticationService = ServerUtils.LoadPlugin(authService, args); - m_UserAccountService = ServerUtils.LoadPlugin(userService, args); + m_AuthenticationService = m_context.ResolveNamed(authService); + m_UserAccountService = m_context.ResolveNamed(userService); // Handler for OpenID user identity pages HttpServer.AddStreamHandler(new OpenIdStreamHandler("GET", "/users", m_UserAccountService, m_AuthenticationService)); diff --git a/Source/OpenSim.Server.Handlers/Authorization/AuthorizationServerConnector.cs b/Source/OpenSim.Server.Handlers/Authorization/AuthorizationServerConnector.cs index 3a1a22f5845..e406bc1cce4 100644 --- a/Source/OpenSim.Server.Handlers/Authorization/AuthorizationServerConnector.cs +++ b/Source/OpenSim.Server.Handlers/Authorization/AuthorizationServerConnector.cs @@ -25,7 +25,6 @@ * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ -using OpenSim.Server.Base; using OpenSim.Services.Interfaces; using OpenSim.Framework.Servers.HttpServer; using OpenSim.Server.Handlers.Base; @@ -33,31 +32,38 @@ using Microsoft.Extensions.Configuration; using Microsoft.Extensions.Logging; +using Autofac; + + namespace OpenSim.Server.Handlers.Authorization { public class AuthorizationServerConnector : IServiceConnector { private IAuthorizationService m_AuthorizationService; + protected readonly IConfiguration m_configuration; + protected readonly ILogger m_logger; + protected readonly IComponentContext m_context; + public AuthorizationServerConnector( IConfiguration configuration, - ILogger logger) + ILogger logger, + IComponentContext componentContext) { - Config = configuration; - Logger = logger; + m_configuration = configuration; + m_logger = logger; + m_context = componentContext; } public string ConfigName => "AuthorizationService"; - public IConfiguration Config { get; private set; } - public ILogger Logger { get; private set; } public IHttpServer HttpServer { get; private set; } public void Initialize(IHttpServer httpServer) { HttpServer = httpServer; - var serverConfig = Config.GetSection(ConfigName); + var serverConfig = m_configuration.GetSection(ConfigName); if (serverConfig.Exists() is false) throw new Exception($"No section {ConfigName} in config file"); @@ -65,8 +71,7 @@ public void Initialize(IHttpServer httpServer) if (string.IsNullOrEmpty(authorizationService)) throw new Exception("No AuthorizationService in config file"); - Object[] args = new Object[] { Config }; - m_AuthorizationService = ServerUtils.LoadPlugin(authorizationService, args); + m_AuthorizationService = m_context.ResolveNamed(authorizationService); HttpServer.AddStreamHandler(new AuthorizationServerPostHandler(m_AuthorizationService)); } diff --git a/Source/OpenSim.Server.Handlers/Avatar/AvatarServerConnector.cs b/Source/OpenSim.Server.Handlers/Avatar/AvatarServerConnector.cs index d67f6974ed5..f1a8ef8d06b 100644 --- a/Source/OpenSim.Server.Handlers/Avatar/AvatarServerConnector.cs +++ b/Source/OpenSim.Server.Handlers/Avatar/AvatarServerConnector.cs @@ -33,6 +33,7 @@ using Microsoft.Extensions.Configuration; using Microsoft.Extensions.Logging; +using Autofac; namespace OpenSim.Server.Handlers.Avatar { @@ -40,18 +41,21 @@ public class AvatarServiceConnector : IServiceConnector { private IAvatarService m_AvatarService; + protected readonly IConfiguration m_configuration; + protected readonly ILogger m_logger; + protected readonly IComponentContext m_context; + public AvatarServiceConnector( IConfiguration config, - ILogger logger) + ILogger logger, + IComponentContext componentContext) { - Config = config; - Logger = logger; + m_configuration = config; + m_logger = logger; + m_context = componentContext; } public string ConfigName => "AvatarService"; - - public IConfiguration Config { get; private set; } - public ILogger Logger { get; private set; } public IHttpServer HttpServer { get; private set; } @@ -59,7 +63,7 @@ public void Initialize(IHttpServer httpServer) { HttpServer = httpServer; - var serverConfig = Config.GetSection(ConfigName); + var serverConfig = m_configuration.GetSection(ConfigName); if (serverConfig.Exists() is false) throw new Exception($"No section {ConfigName} in config file"); @@ -67,10 +71,9 @@ public void Initialize(IHttpServer httpServer) if (string.IsNullOrEmpty(avatarService)) throw new Exception("No LocalServiceModule in config file"); - Object[] args = new Object[] { Config }; - m_AvatarService = ServerUtils.LoadPlugin(avatarService, args); + m_AvatarService = m_context.ResolveNamed(avatarService); - IServiceAuth auth = ServiceAuth.Create(Config, ConfigName); + IServiceAuth auth = ServiceAuth.Create(m_configuration, ConfigName); HttpServer.AddStreamHandler(new AvatarServerPostHandler(m_AvatarService, auth)); } diff --git a/Source/OpenSim.Server.Handlers/BakedTextures/XBakesHandler.cs b/Source/OpenSim.Server.Handlers/BakedTextures/XBakesHandler.cs index f0a91da0c78..226cbc9a710 100644 --- a/Source/OpenSim.Server.Handlers/BakedTextures/XBakesHandler.cs +++ b/Source/OpenSim.Server.Handlers/BakedTextures/XBakesHandler.cs @@ -35,29 +35,35 @@ using Microsoft.Extensions.Configuration; using Microsoft.Extensions.Logging; +using Autofac; + namespace OpenSim.Server.Handlers.BakedTextures { public class XBakesConnector : IServiceConnector { + protected readonly IConfiguration m_configuration; + protected readonly ILogger m_logger; + protected readonly IComponentContext m_context; + public XBakesConnector( IConfiguration config, - ILogger logger) + ILogger logger, + IComponentContext componentContext) { - Config = config; - Logger = logger; + m_configuration = config; + m_logger = logger; + m_context = componentContext; } public string ConfigName => "BakedTextureService"; - public IConfiguration Config { get; private set; } - public ILogger Logger { get; private set; } public IHttpServer HttpServer { get; private set; } public void Initialize(IHttpServer httpServer) { HttpServer = httpServer; - var serverConfig = Config.GetSection(ConfigName); + var serverConfig = m_configuration.GetSection(ConfigName); if (serverConfig.Exists() is false) throw new Exception($"No section {ConfigName} in config file"); @@ -65,14 +71,12 @@ public void Initialize(IHttpServer httpServer) if (string.IsNullOrWhiteSpace(bakesServiceName)) throw new Exception("No BakedTextureService in config file"); - object[] args = new object[] { Config }; - IBakedTextureService bakesService = ServerUtils.LoadPlugin(bakesServiceName, args); + IBakedTextureService bakesService = m_context.ResolveNamed(bakesServiceName); - IServiceAuth auth = ServiceAuth.Create(Config, ConfigName); + IServiceAuth auth = ServiceAuth.Create(m_configuration, ConfigName); HttpServer.AddSimpleStreamHandler(new BakesServerHandler(bakesService, auth), true); } - } public class BakesServerHandler : SimpleStreamHandler diff --git a/Source/OpenSim.Server.Handlers/Base/IServiceConnector.cs b/Source/OpenSim.Server.Handlers/Base/IServiceConnector.cs index ff69035f595..4a618d3dc83 100644 --- a/Source/OpenSim.Server.Handlers/Base/IServiceConnector.cs +++ b/Source/OpenSim.Server.Handlers/Base/IServiceConnector.cs @@ -27,16 +27,12 @@ using OpenSim.Framework.Servers.HttpServer; -using Microsoft.Extensions.Configuration; -using Microsoft.Extensions.Logging; - namespace OpenSim.Server.Handlers.Base { public interface IServiceConnector { string ConfigName { get; } - IConfiguration Config { get; } - ILogger Logger { get; } + IHttpServer HttpServer { get; } void Initialize(IHttpServer httpServer); diff --git a/Source/OpenSim.Server.Handlers/Estate/EstateDataRobustConnector.cs b/Source/OpenSim.Server.Handlers/Estate/EstateDataRobustConnector.cs index e003e29af18..87193f8ab12 100644 --- a/Source/OpenSim.Server.Handlers/Estate/EstateDataRobustConnector.cs +++ b/Source/OpenSim.Server.Handlers/Estate/EstateDataRobustConnector.cs @@ -24,7 +24,6 @@ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ -using System.Reflection; using System.Net; using OpenMetaverse; @@ -38,30 +37,35 @@ using Microsoft.Extensions.Configuration; using Microsoft.Extensions.Logging; +using Autofac; + namespace OpenSim.Server.Handlers { public class EstateDataRobustConnector : IServiceConnector - { + { + protected readonly IConfiguration m_configuration; + protected readonly ILogger m_logger; + protected readonly IComponentContext m_context; + public EstateDataRobustConnector( IConfiguration config, - ILogger logger) + ILogger logger, + IComponentContext componentContext) { - Config = config; - Logger = logger; + m_configuration = config; + m_logger = logger; + m_context = componentContext; } public string ConfigName => "EstateService"; - public IConfiguration Config { get; private set; } - public ILogger Logger { get; private set; } - public IHttpServer HttpServer { get; private set; } public void Initialize(IHttpServer httpServer) { HttpServer = httpServer; - var serverConfig = Config.GetSection(ConfigName); + var serverConfig = m_configuration.GetSection(ConfigName); if (serverConfig.Exists() is false) throw new Exception($"No section {ConfigName} in config file"); @@ -69,10 +73,9 @@ public void Initialize(IHttpServer httpServer) if (String.IsNullOrWhiteSpace(service)) throw new Exception("No LocalServiceModule in config file"); - Object[] args = new Object[] { Config }; - IEstateDataService e_service = ServerUtils.LoadPlugin(service, args); + IEstateDataService e_service = m_context.ResolveNamed(service); - IServiceAuth auth = ServiceAuth.Create(Config, ConfigName); + IServiceAuth auth = ServiceAuth.Create(m_configuration, ConfigName); HttpServer.AddStreamHandler(new EstateServerGetHandler(e_service, auth)); HttpServer.AddStreamHandler(new EstateServerPostHandler(e_service, auth)); diff --git a/Source/OpenSim.Server.Handlers/Freeswitch/FreeswitchServerConnector.cs b/Source/OpenSim.Server.Handlers/Freeswitch/FreeswitchServerConnector.cs index 30c66361fcc..427b13452bd 100644 --- a/Source/OpenSim.Server.Handlers/Freeswitch/FreeswitchServerConnector.cs +++ b/Source/OpenSim.Server.Handlers/Freeswitch/FreeswitchServerConnector.cs @@ -35,6 +35,8 @@ using Microsoft.Extensions.Configuration; using Microsoft.Extensions.Logging; +using Autofac; + namespace OpenSim.Server.Handlers.Freeswitch { public class FreeswitchServerConnector : IServiceConnector @@ -42,26 +44,29 @@ public class FreeswitchServerConnector : IServiceConnector private IFreeswitchService m_FreeswitchService; protected readonly string m_freeSwitchAPIPrefix = "/fsapi"; + protected readonly IConfiguration m_configuration; + protected readonly ILogger m_logger; + protected readonly IComponentContext m_context; public FreeswitchServerConnector( IConfiguration config, - ILogger logger) + ILogger logger, + IComponentContext componentContext) { - Config = config; - Logger = logger; + m_configuration = config; + m_logger = logger; + m_context = componentContext; } public string ConfigName => "FreeswitchService"; - public IConfiguration Config { get; private set; } - public ILogger Logger { get; private set; } public IHttpServer HttpServer { get; private set; } public void Initialize(IHttpServer httpServer) { HttpServer = httpServer; - var serverConfig = Config.GetSection(ConfigName); + var serverConfig = m_configuration.GetSection(ConfigName); if (serverConfig.Exists() is false) throw new Exception($"No section {ConfigName} in config file"); @@ -69,8 +74,7 @@ public void Initialize(IHttpServer httpServer) if (string.IsNullOrEmpty(freeswitchService)) throw new Exception("No LocalServiceModule in config file"); - Object[] args = new Object[] { Config }; - m_FreeswitchService = ServerUtils.LoadPlugin(freeswitchService, args); + m_FreeswitchService = m_context.ResolveNamed(freeswitchService); HttpServer.AddHTTPHandler(String.Format("{0}/freeswitch-config", m_freeSwitchAPIPrefix), FreeSwitchConfigHTTPHandler); HttpServer.AddHTTPHandler(String.Format("{0}/region-config", m_freeSwitchAPIPrefix), RegionConfigHTTPHandler); @@ -93,7 +97,7 @@ public Hashtable FreeSwitchConfigHTTPHandler(Hashtable request) else if (section == "dialplan") response = m_FreeswitchService.HandleDialplanRequest(requestBody); else - Logger.LogWarning($"section was {section}"); + m_logger.LogWarning($"section was {section}"); return response; } diff --git a/Source/OpenSim.Server.Handlers/Friends/FriendServerConnector.cs b/Source/OpenSim.Server.Handlers/Friends/FriendServerConnector.cs index 8698f04923e..c4537a9ef24 100644 --- a/Source/OpenSim.Server.Handlers/Friends/FriendServerConnector.cs +++ b/Source/OpenSim.Server.Handlers/Friends/FriendServerConnector.cs @@ -34,6 +34,9 @@ using Microsoft.Extensions.Configuration; using Microsoft.Extensions.Logging; +using Autofac; +using System.ComponentModel; + namespace OpenSim.Server.Handlers.Friends { public class FriendsServiceConnector : IServiceConnector @@ -41,27 +44,29 @@ public class FriendsServiceConnector : IServiceConnector private const string ServiceName = "FriendsService"; private IFriendsService m_FriendsService; + protected readonly IConfiguration m_configuration; + protected readonly ILogger m_logger; + protected readonly IComponentContext m_context; public FriendsServiceConnector( IConfiguration config, - ILogger logger) + ILogger logger, + IComponentContext componentContext) { - Config = config; - Logger = logger; + m_configuration = config; + m_logger = logger; + m_context = componentContext; } public string ConfigName { get; private set; } = ServiceName; - public IConfiguration Config { get; private set; } - public ILogger Logger { get; private set; } public IHttpServer HttpServer { get; private set; } - public void Initialize(IHttpServer httpServer) { HttpServer = httpServer; - var serverConfig = Config.GetSection(ConfigName); + var serverConfig = m_configuration.GetSection(ConfigName); if (serverConfig.Exists() is false) throw new Exception($"No section {ConfigName} in config file"); @@ -69,14 +74,11 @@ public void Initialize(IHttpServer httpServer) if (string.IsNullOrEmpty(theService)) throw new Exception("No LocalServiceModule in config file"); - Object[] args = new Object[] { Config }; - m_FriendsService = ServerUtils.LoadPlugin(theService, args); + m_FriendsService = m_context.ResolveNamed(theService); - IServiceAuth auth = ServiceAuth.Create(Config, ConfigName); + IServiceAuth auth = ServiceAuth.Create(m_configuration, ConfigName); HttpServer.AddStreamHandler(new FriendsServerPostHandler(m_FriendsService, auth)); } - - } } diff --git a/Source/OpenSim.Server.Handlers/Grid/GridServerConnector.cs b/Source/OpenSim.Server.Handlers/Grid/GridServerConnector.cs index 308368435ac..9c989e6dae6 100644 --- a/Source/OpenSim.Server.Handlers/Grid/GridServerConnector.cs +++ b/Source/OpenSim.Server.Handlers/Grid/GridServerConnector.cs @@ -34,31 +34,37 @@ using Microsoft.Extensions.Configuration; using Microsoft.Extensions.Logging; +using Autofac; + namespace OpenSim.Server.Handlers.Grid { public class GridServiceConnector : IServiceConnector { private IGridService m_GridService; + protected readonly IConfiguration m_configuration; + protected readonly ILogger m_logger; + protected readonly IComponentContext m_context; + public GridServiceConnector( IConfiguration config, - ILogger logger) + ILogger logger, + IComponentContext componentContext) { - Config = config; - Logger = logger; + m_configuration = config; + m_logger = logger; + m_context = componentContext; } public string ConfigName { get; private set; } = "GridService"; - public IConfiguration Config { get; private set; } - public ILogger Logger { get; private set; } public IHttpServer HttpServer { get; private set; } public void Initialize(IHttpServer httpServer) { HttpServer = httpServer; - var serverConfig = Config.GetSection(ConfigName); + var serverConfig = m_configuration.GetSection(ConfigName); if (serverConfig.Exists() is false) throw new Exception($"No section {ConfigName} in config file"); @@ -66,10 +72,9 @@ public void Initialize(IHttpServer httpServer) if (string.IsNullOrEmpty(gridService)) throw new Exception("No LocalServiceModule in config file"); - Object[] args = new Object[] { Config }; - m_GridService = ServerUtils.LoadPlugin(gridService, args); + m_GridService = m_context.ResolveNamed(gridService); - IServiceAuth auth = ServiceAuth.Create(Config, ConfigName); + IServiceAuth auth = ServiceAuth.Create(m_configuration, ConfigName); HttpServer.AddStreamHandler(new GridServerPostHandler(m_GridService, auth)); } diff --git a/Source/OpenSim.Server.Handlers/GridUser/GridUserServerConnector.cs b/Source/OpenSim.Server.Handlers/GridUser/GridUserServerConnector.cs index 0c8de5e6407..2b0cbedf916 100644 --- a/Source/OpenSim.Server.Handlers/GridUser/GridUserServerConnector.cs +++ b/Source/OpenSim.Server.Handlers/GridUser/GridUserServerConnector.cs @@ -34,31 +34,39 @@ using Microsoft.Extensions.Configuration; using Microsoft.Extensions.Logging; +using Autofac; +using System.ComponentModel; + namespace OpenSim.Server.Handlers.GridUser { public class GridUserServiceConnector : IServiceConnector { private IGridUserService m_GridUserService; private static string _ConfigName = "GridUserService"; + + protected readonly IConfiguration m_configuration; + protected readonly ILogger m_logger; + protected readonly IComponentContext m_context; + public GridUserServiceConnector( IConfiguration config, - ILogger logger) + ILogger logger, + IComponentContext componentContext) { - Config = config; - Logger = logger; + m_configuration = config; + m_logger = logger; + m_context = componentContext; } public string ConfigName { get; private set; } = _ConfigName; - - public IConfiguration Config { get; private set; } - public ILogger Logger { get; private set; } + public IHttpServer HttpServer { get; private set; } public void Initialize(IHttpServer httpServer) { HttpServer = httpServer; - var serverConfig = Config.GetSection(ConfigName); + var serverConfig = m_configuration.GetSection(ConfigName); if (serverConfig.Exists() is false) throw new Exception($"No section {ConfigName} in config file"); @@ -66,10 +74,9 @@ public void Initialize(IHttpServer httpServer) if (string.IsNullOrEmpty(service)) throw new Exception("No LocalServiceModule in config file"); - Object[] args = new Object[] { Config }; - m_GridUserService = ServerUtils.LoadPlugin(service, args); + m_GridUserService = m_context.ResolveNamed(service); - IServiceAuth auth = ServiceAuth.Create(Config, ConfigName); + IServiceAuth auth = ServiceAuth.Create(m_configuration, ConfigName); HttpServer.AddStreamHandler(new GridUserServerPostHandler(m_GridUserService, auth)); } diff --git a/Source/OpenSim.Server.Handlers/Hypergrid/GatekeeperServerConnector.cs b/Source/OpenSim.Server.Handlers/Hypergrid/GatekeeperServerConnector.cs index 7b6c3956b7a..9b616c328e7 100644 --- a/Source/OpenSim.Server.Handlers/Hypergrid/GatekeeperServerConnector.cs +++ b/Source/OpenSim.Server.Handlers/Hypergrid/GatekeeperServerConnector.cs @@ -33,6 +33,9 @@ using Microsoft.Extensions.Configuration; using Microsoft.Extensions.Logging; +using Autofac; +using System.ComponentModel; + namespace OpenSim.Server.Handlers.Hypergrid { public class GatekeeperServiceInConnector : IServiceConnector @@ -40,12 +43,19 @@ public class GatekeeperServiceInConnector : IServiceConnector private IGatekeeperService m_GatekeeperService = null; private bool m_Proxy = false; + + protected readonly IConfiguration m_configuration; + protected readonly ILogger m_logger; + protected readonly IComponentContext m_context; + public GatekeeperServiceInConnector( IConfiguration config, - ILogger logger) + ILogger logger, + IComponentContext componentContext) { - Config = config; - Logger = logger; + m_configuration = config; + m_logger = logger; + m_context = componentContext; } public IGatekeeperService GateKeeper @@ -55,8 +65,6 @@ public IGatekeeperService GateKeeper public string ConfigName { get; private set; } = "GatekeeperService"; - public IConfiguration Config { get; private set; } - public ILogger Logger { get; private set; } public IHttpServer HttpServer { get; private set; } // public GatekeeperServiceInConnector(IConfigSource config, IHttpServer server, ISimulationService simService) : @@ -65,15 +73,14 @@ public void Initialize(IHttpServer httpServer) { HttpServer = httpServer; - var gridConfig = Config.GetSection(ConfigName); + var gridConfig = m_configuration.GetSection(ConfigName); if (gridConfig.Exists() is false) { - string serviceDll = gridConfig.GetValue("LocalServiceModule", string.Empty); - if (string.IsNullOrWhiteSpace(serviceDll)) + string service = gridConfig.GetValue("LocalServiceModule", string.Empty); + if (string.IsNullOrWhiteSpace(service)) throw new Exception("No LocalServiceModule in config file"); - Object[] args = new Object[] { Config, "XXX" /*simService*/ }; - m_GatekeeperService = ServerUtils.LoadPlugin(serviceDll, args); + m_GatekeeperService = m_context.ResolveNamed(service); } if (m_GatekeeperService == null) diff --git a/Source/OpenSim.Server.Handlers/Hypergrid/HGFriendServerConnector.cs b/Source/OpenSim.Server.Handlers/Hypergrid/HGFriendServerConnector.cs index a2bf378d7dc..8e22df84cfe 100644 --- a/Source/OpenSim.Server.Handlers/Hypergrid/HGFriendServerConnector.cs +++ b/Source/OpenSim.Server.Handlers/Hypergrid/HGFriendServerConnector.cs @@ -32,6 +32,7 @@ using Microsoft.Extensions.Configuration; using Microsoft.Extensions.Logging; +using Autofac; namespace OpenSim.Server.Handlers.Hypergrid { @@ -40,19 +41,25 @@ public class HGFriendsServerConnector : IServiceConnector private IUserAgentService m_UserAgentService; private IHGFriendsService m_TheService; + protected readonly IConfiguration m_configuration; + protected readonly ILogger m_logger; + protected readonly IComponentContext m_context; + + // Called from Robust public HGFriendsServerConnector( IConfiguration config, - ILogger logger) + ILogger logger, + IComponentContext componentContext + ) { - Config = config; - Logger = logger; + m_configuration = config; + m_logger = logger; + m_context = componentContext; } public string ConfigName { get; private set; } = "HGFriendsService"; - public IConfiguration Config { get; private set; } - public ILogger Logger { get; private set; } public IHttpServer HttpServer { get; private set; } // public HGFriendsServerConnector(IConfiguration config, IHttpServer server, string configName, IFriendsSimConnector localConn) @@ -61,9 +68,9 @@ public void Initialize(IHttpServer httpServer) { HttpServer = httpServer; - Object[] args = new Object[] { Config, ConfigName, null /*localConn*/ }; + Object[] args = new Object[] { m_configuration, ConfigName, null /*localConn*/ }; - var serverConfig = Config.GetSection(ConfigName); + var serverConfig = m_configuration.GetSection(ConfigName); if (serverConfig.Exists() is false) throw new Exception($"No section {ConfigName} in config file"); @@ -71,17 +78,15 @@ public void Initialize(IHttpServer httpServer) if (string.IsNullOrEmpty(theService)) throw new Exception("No LocalServiceModule in config file"); - m_TheService = ServerUtils.LoadPlugin(theService, args); + m_TheService = m_context.ResolveNamed(theService); theService = serverConfig.GetValue("UserAgentService", string.Empty); if (string.IsNullOrEmpty(theService)) throw new Exception($"No UserAgentService in {ConfigName}"); - m_UserAgentService = ServerUtils.LoadPlugin(theService, new Object[] { Config, null /*localConn*/ }); + m_UserAgentService = m_context.ResolveNamed(theService); - HttpServer.AddStreamHandler(new HGFriendsServerPostHandler(m_TheService, m_UserAgentService, null /*localConn*/)); + HttpServer.AddStreamHandler(new HGFriendsServerPostHandler(m_TheService, m_UserAgentService, null /*m_friendsSimConnector*/ )); } - - } } diff --git a/Source/OpenSim.Server.Handlers/Hypergrid/InstantMessageServerConnector.cs b/Source/OpenSim.Server.Handlers/Hypergrid/InstantMessageServerConnector.cs index 2ca192aa4e5..062a0abb1b5 100644 --- a/Source/OpenSim.Server.Handlers/Hypergrid/InstantMessageServerConnector.cs +++ b/Source/OpenSim.Server.Handlers/Hypergrid/InstantMessageServerConnector.cs @@ -29,7 +29,6 @@ using System.Net; using OpenSim.Framework; -using OpenSim.Server.Base; using OpenSim.Services.Interfaces; using OpenSim.Framework.Servers.HttpServer; using OpenSim.Server.Handlers.Base; @@ -38,6 +37,7 @@ using Microsoft.Extensions.Configuration; using Microsoft.Extensions.Logging; +using Autofac; namespace OpenSim.Server.Handlers.Hypergrid { @@ -45,36 +45,32 @@ public class InstantMessageServerConnector : IServiceConnector { private IInstantMessage m_IMService; - public string ConfigName { get; private set; } = "HGInstantMessageService"; - - public IConfiguration Config { get; private set; } - public ILogger Logger { get; private set; } - public IHttpServer HttpServer { get; private set; } + protected IConfiguration m_configuration; + protected ILogger m_logger; + protected IComponentContext m_context; public InstantMessageServerConnector( IConfiguration config, - ILogger logger) + ILogger logger, + IComponentContext componentContext) { - Config = config; - Logger = logger; + m_configuration = config; + m_logger = logger; + m_context = componentContext; } -// public InstantMessageServerConnector(IConfiguration config, IHttpServer server, IInstantMessageSimConnector simConnector) : -// XXX + public string ConfigName { get; private set; } = "InstantMessageServerConnector"; // "HGInstantMessageService"; + public IHttpServer HttpServer { get; private set; } public void Initialize(IHttpServer httpServer) { HttpServer = httpServer; - IInstantMessageSimConnector simConnector = null; - var gridConfig = Config.GetSection(ConfigName); + var gridConfig = m_configuration.GetSection(ConfigName); if (gridConfig.Exists()) { - string serviceDll = gridConfig.GetValue("LocalServiceModule", string.Empty); - - Object[] args = new Object[] { Config, simConnector }; - - m_IMService = ServerUtils.LoadPlugin(serviceDll, args); + string service = gridConfig.GetValue("LocalServiceModule", string.Empty); + m_IMService = m_context.ResolveNamed(service); } if (m_IMService == null) @@ -228,7 +224,7 @@ protected virtual XmlRpcResponse ProcessInstantMessage(XmlRpcRequest request, IP } catch (Exception e) { - Logger.LogError(e, "Caught unexpected exception"); + m_logger.LogError(e, "Caught unexpected exception"); successful = false; } diff --git a/Source/OpenSim.Server.Handlers/Hypergrid/UserAgentServerConnector.cs b/Source/OpenSim.Server.Handlers/Hypergrid/UserAgentServerConnector.cs index ba1354ee458..af3b7c36528 100644 --- a/Source/OpenSim.Server.Handlers/Hypergrid/UserAgentServerConnector.cs +++ b/Source/OpenSim.Server.Handlers/Hypergrid/UserAgentServerConnector.cs @@ -41,6 +41,8 @@ using Microsoft.Extensions.Configuration; using Microsoft.Extensions.Logging; +using Autofac; + namespace OpenSim.Server.Handlers.Hypergrid { public class UserAgentServerConnector : IServiceConnector @@ -48,15 +50,18 @@ public class UserAgentServerConnector : IServiceConnector private string[] m_AuthorizedCallers; private bool m_VerifyCallers = false; + private readonly IConfiguration m_configuration; private readonly ILogger m_logger; + private readonly IComponentContext m_context; public UserAgentServerConnector( IConfiguration config, - ILogger logger) + ILogger logger, + IComponentContext componentContext) { - Config = config; - Logger = logger; + m_configuration = config; m_logger = logger; + m_context = componentContext; } private IUserAgentService m_HomeUsersService; @@ -66,31 +71,19 @@ public IUserAgentService HomeUsersService get { return m_HomeUsersService; } } - public string ConfigName { get; private set; } = "UserAgentService"; - - public IConfiguration Config { get; private set; } - - public ILogger Logger { get; private set; } + public string ConfigName { get; private set; } = "UserAgentServerConnector"; // "UserAgentService"; public IHttpServer HttpServer { get; private set; } - // XXX - // public UserAgentServerConnector(IConfiguration config, IHttpServer server, IFriendsSimConnector friendsConnector) : - // base(config, server, "UserAgentService") - public void Initialize(IHttpServer httpServer) { HttpServer = httpServer; - IFriendsSimConnector friendsConnector = null; - var gridConfig = Config.GetSection("UserAgentService"); + var gridConfig = m_configuration.GetSection(ConfigName); if (gridConfig.Exists()) { - string serviceDll = gridConfig.GetValue("LocalServiceModule", string.Empty); - - Object[] args = new Object[] { Config, friendsConnector }; - - m_HomeUsersService = ServerUtils.LoadPlugin(serviceDll, args); + string service = gridConfig.GetValue("LocalServiceModule", string.Empty); + m_HomeUsersService = m_context.ResolveNamed(service); } if (m_HomeUsersService == null) @@ -98,7 +91,6 @@ public void Initialize(IHttpServer httpServer) string loginServerIP = gridConfig.GetValue("LoginServerIP", "127.0.0.1"); bool proxy = gridConfig.GetValue("HasProxy", false); - m_VerifyCallers = gridConfig.GetValue("VerifyCallers", false); string csv = gridConfig.GetValue("AuthorizedCallers", "127.0.0.1"); diff --git a/Source/OpenSim.Server.Handlers/Inventory/InventoryServerInConnector.cs b/Source/OpenSim.Server.Handlers/Inventory/InventoryServerInConnector.cs index afe4ee7dd46..f9ab91709d0 100644 --- a/Source/OpenSim.Server.Handlers/Inventory/InventoryServerInConnector.cs +++ b/Source/OpenSim.Server.Handlers/Inventory/InventoryServerInConnector.cs @@ -27,7 +27,6 @@ using System.Net; -using OpenSim.Server.Base; using OpenSim.Services.Interfaces; using OpenSim.Framework; using OpenSim.Framework.Servers.HttpServer; @@ -37,6 +36,7 @@ using Microsoft.Extensions.Configuration; using Microsoft.Extensions.Logging; +using Autofac; namespace OpenSim.Server.Handlers.Inventory { @@ -50,30 +50,31 @@ public class InventoryServiceInConnector : IServiceConnector //private AuthedSessionCache m_session_cache = new AuthedSessionCache(INVENTORY_DEFAULT_SESSION_TIME); private string m_userserver_url; - protected static string _configName = "InventoryService"; + protected const string _configName = "InventoryService"; public string ConfigName { get; private set; } = _configName; - - public IConfiguration Config { get; private set; } - - public ILogger Logger { get; private set; } + private readonly IConfiguration m_configuration; + private readonly ILogger m_logger; + private readonly IComponentContext m_context; public IHttpServer HttpServer { get; private set; } public InventoryServiceInConnector( IConfiguration config, - ILogger logger) + ILogger logger, + IComponentContext componentContext) { - Config = config; - Logger = logger; + m_configuration = config; + m_logger = logger; + m_context = componentContext; } public void Initialize(IHttpServer httpServer) { HttpServer = httpServer; - var serverConfig = Config.GetSection(ConfigName); + var serverConfig = m_configuration.GetSection(ConfigName); if (serverConfig.Exists() is false) throw new Exception($"No section '{ConfigName}' in config file"); @@ -82,15 +83,14 @@ public void Initialize(IHttpServer httpServer) if (string.IsNullOrEmpty(inventoryService)) throw new Exception("No LocalServiceModule in config file"); - Object[] args = new Object[] { Config }; - m_InventoryService = ServerUtils.LoadPlugin(inventoryService, args); + m_InventoryService = m_context.ResolveNamed(inventoryService); m_userserver_url = serverConfig.GetValue("UserServerURI", String.Empty); m_doLookup = serverConfig.GetValue("SessionAuthentication", false); AddHttpHandlers(HttpServer); - Logger.LogDebug("Handlers initialized"); + m_logger.LogDebug("Handlers initialized"); } protected virtual void AddHttpHandlers(IHttpServer HttpServer) @@ -212,7 +212,7 @@ private Dictionary GetSystemFolders(UUID userID) } } - Logger.LogWarning($"System folders for {userID} not found"); + m_logger.LogWarning($"System folders for {userID} not found"); return new Dictionary(); } @@ -312,7 +312,7 @@ public bool CheckTrustSource(IPEndPoint peer) { if (m_doLookup) { - Logger.LogInformation($"Checking trusted source {peer}"); + m_logger.LogInformation($"Checking trusted source {peer}"); UriBuilder ub = new UriBuilder(m_userserver_url); IPAddress[] uaddrs = Dns.GetHostAddresses(ub.Host); @@ -324,7 +324,7 @@ public bool CheckTrustSource(IPEndPoint peer) } } - Logger.LogWarning($"Rejecting request since source {peer} was not in the list of trusted sources"); + m_logger.LogWarning($"Rejecting request since source {peer} was not in the list of trusted sources"); return false; } diff --git a/Source/OpenSim.Server.Handlers/Inventory/XInventoryInConnector.cs b/Source/OpenSim.Server.Handlers/Inventory/XInventoryInConnector.cs index dcfdd16c678..27d057f3c66 100644 --- a/Source/OpenSim.Server.Handlers/Inventory/XInventoryInConnector.cs +++ b/Source/OpenSim.Server.Handlers/Inventory/XInventoryInConnector.cs @@ -38,6 +38,8 @@ using Microsoft.Extensions.Configuration; using Microsoft.Extensions.Logging; +using Autofac; + namespace OpenSim.Server.Handlers.Inventory { public class XInventoryInConnector : IServiceConnector @@ -45,26 +47,31 @@ public class XInventoryInConnector : IServiceConnector private IInventoryService m_InventoryService; private static string _configName = "InventoryService"; + private readonly IConfiguration m_configuration; + private readonly ILogger m_logger; + private readonly IComponentContext m_context; + + public string ConfigName { get; private set; } = _configName; - public IConfiguration Config { get; private set; } - public ILogger Logger { get; private set; } public IHttpServer HttpServer { get; private set; } public XInventoryInConnector( IConfiguration config, - ILogger logger) + ILogger logger, + IComponentContext componentContext) { - Config = config; - Logger = logger; + m_configuration = config; + m_logger = logger; + m_context = componentContext; } public void Initialize(IHttpServer httpServer) { HttpServer = httpServer; - Logger.LogDebug($"Starting with config name {ConfigName}"); + m_logger.LogDebug($"[XInventoryInConnector] Starting with config name {ConfigName}"); - var serverConfig = Config.GetSection(ConfigName); + var serverConfig = m_configuration.GetSection(ConfigName); if (serverConfig.Exists() is false) throw new Exception($"No section '{ConfigName}' in config file"); @@ -72,12 +79,11 @@ public void Initialize(IHttpServer httpServer) if (string.IsNullOrEmpty(inventoryService)) throw new Exception("No InventoryService in config file"); - Object[] args = new Object[] { Config, ConfigName }; - m_InventoryService = ServerUtils.LoadPlugin(inventoryService, args); + m_InventoryService = m_context.ResolveNamed(inventoryService); - IServiceAuth auth = ServiceAuth.Create(Config, ConfigName); + IServiceAuth auth = ServiceAuth.Create(m_configuration, ConfigName); - HttpServer.AddStreamHandler(new XInventoryConnectorPostHandler(Logger, m_InventoryService, auth)); + HttpServer.AddStreamHandler(new XInventoryConnectorPostHandler(m_logger, m_InventoryService, auth)); } } @@ -101,12 +107,9 @@ protected override byte[] ProcessRequest(string path, Stream requestData, body = sr.ReadToEnd(); body = body.Trim(); - //m_log.DebugFormat("[XXX]: query String: {0}", body); - try { - Dictionary request = - ServerUtils.ParseQueryString(body); + Dictionary request = ServerUtils.ParseQueryString(body); if (!request.ContainsKey("METHOD")) return FailureResult(); diff --git a/Source/OpenSim.Server.Handlers/Login/LLLoginServiceInConnector.cs b/Source/OpenSim.Server.Handlers/Login/LLLoginServiceInConnector.cs index 407a682d5c3..bde302e31fa 100644 --- a/Source/OpenSim.Server.Handlers/Login/LLLoginServiceInConnector.cs +++ b/Source/OpenSim.Server.Handlers/Login/LLLoginServiceInConnector.cs @@ -33,6 +33,7 @@ using Microsoft.Extensions.Configuration; using Microsoft.Extensions.Logging; +using Autofac; namespace OpenSim.Server.Handlers.Login { @@ -42,48 +43,52 @@ public class LLLoginServiceInConnector : IServiceConnector private IScene m_Scene; private bool m_Proxy; private BasicDosProtectorOptions m_DosProtectionOptions; - private static string _configName = "LoginService"; + protected IConfiguration m_configuration; + protected ILogger m_logger; + protected IComponentContext m_context; + public LLLoginServiceInConnector( IConfiguration configuration, ILogger logger, + IComponentContext componentContext, IScene scene = null ) { - Config = configuration; - Logger = logger; + m_configuration = configuration; + m_logger = logger; + m_context = componentContext; m_Scene = scene; } public string ConfigName { get; private set; } = _configName; - public IConfiguration Config { get; private set; } - public ILogger Logger { get; private set; } public IHttpServer HttpServer { get; private set; } public void Initialize(IHttpServer httpServer) { HttpServer = httpServer; - Logger.LogDebug($"Starting..."); - string loginService = ReadLocalServiceFromConfig(Config, ConfigName); - - ISimulationService simService = null; - ILibraryService libService = null; - Object[] args = null; - - if (m_Scene != null) - { - simService = m_Scene.RequestModuleInterface(); - libService = m_Scene.RequestModuleInterface(); - args = new Object[] { Config, simService, libService }; - } - else - { - args = new Object[] { Config }; - } - - m_LoginService = ServerUtils.LoadPlugin(loginService, args); + m_logger.LogDebug($"Starting..."); + string loginService = ReadLocalServiceFromConfig(m_configuration, ConfigName); + + // ISimulationService simService = null; + // ILibraryService libService = null; + + // Object[] args = null; + + // if (m_Scene != null) + // { + // simService = m_Scene.RequestModuleInterface(); + // libService = m_Scene.RequestModuleInterface(); + // args = new Object[] { Config, simService, libService }; + // } + // else + // { + // args = new Object[] { Config }; + // } + + m_LoginService = m_context.ResolveNamed(loginService); InitializeHandlers(HttpServer); } diff --git a/Source/OpenSim.Server.Handlers/Map/MapAddServerConnector.cs b/Source/OpenSim.Server.Handlers/Map/MapAddServerConnector.cs index fbc5138619a..e6938e0027a 100644 --- a/Source/OpenSim.Server.Handlers/Map/MapAddServerConnector.cs +++ b/Source/OpenSim.Server.Handlers/Map/MapAddServerConnector.cs @@ -37,8 +37,10 @@ using OpenSim.Server.Handlers.Base; using GridRegion = OpenSim.Services.Interfaces.GridRegion; + using Microsoft.Extensions.Configuration; using Microsoft.Extensions.Logging; +using Autofac; namespace OpenSim.Server.Handlers.MapImage { @@ -48,18 +50,22 @@ public class MapAddServiceConnector : IServiceConnector private IGridService m_GridService; private static string _configName = "MapImageService"; + protected IConfiguration m_configuration; + protected ILogger m_logger; + protected IComponentContext m_context; + public MapAddServiceConnector( IConfiguration config, - ILogger logger) + ILogger logger, + IComponentContext componentContext) { - Config = config; - Logger = logger; + m_configuration = config; + m_logger = logger; + m_context = componentContext; } public string ConfigName { get; private set; } = _configName; - public IConfiguration Config { get; private set; } - public ILogger Logger { get; private set; } public IHttpServer HttpServer { get; private set; } @@ -67,7 +73,7 @@ public void Initialize(IHttpServer httpServer) { HttpServer = httpServer; - var serverConfig = Config.GetSection(ConfigName); + var serverConfig = m_configuration.GetSection(ConfigName); if (serverConfig.Exists() is false) throw new Exception($"No section {ConfigName} in config file"); @@ -75,24 +81,25 @@ public void Initialize(IHttpServer httpServer) if (string.IsNullOrWhiteSpace(mapService)) throw new Exception("No LocalServiceModule in config file"); - object[] args = new object[] { Config }; - m_MapService = ServerUtils.LoadPlugin(mapService, args); + m_MapService = m_context.ResolveNamed(mapService); string gridService = serverConfig.GetValue("GridService", string.Empty); if (!string.IsNullOrWhiteSpace(gridService)) - m_GridService = ServerUtils.LoadPlugin(gridService, args); + { + m_GridService = m_context.ResolveNamed(gridService); + } if (m_GridService != null) - Logger.LogInformation($"GridService check is ON"); + m_logger.LogInformation($"GridService check is ON"); else - Logger.LogInformation($"GridService check is OFF"); + m_logger.LogInformation($"GridService check is OFF"); bool proxy = serverConfig.GetValue("HasProxy", false); - IServiceAuth auth = ServiceAuth.Create(Config, ConfigName); + IServiceAuth auth = ServiceAuth.Create(m_configuration, ConfigName); HttpServer.AddSimpleStreamHandler( - new MapServerPostHandler(Logger, m_MapService, m_GridService, proxy, auth)); + new MapServerPostHandler(m_logger, m_MapService, m_GridService, proxy, auth)); } } diff --git a/Source/OpenSim.Server.Handlers/Map/MapGetServerConnector.cs b/Source/OpenSim.Server.Handlers/Map/MapGetServerConnector.cs index 67620642d6f..561d45386ae 100644 --- a/Source/OpenSim.Server.Handlers/Map/MapGetServerConnector.cs +++ b/Source/OpenSim.Server.Handlers/Map/MapGetServerConnector.cs @@ -27,7 +27,6 @@ using System.Net; -using OpenSim.Server.Base; using OpenSim.Services.Interfaces; using OpenSim.Framework.Servers.HttpServer; using OpenSim.Server.Handlers.Base; @@ -36,6 +35,8 @@ using Microsoft.Extensions.Configuration; using Microsoft.Extensions.Logging; +using Autofac; + namespace OpenSim.Server.Handlers.MapImage { @@ -45,25 +46,30 @@ public class MapGetServiceConnector : IServiceConnector private static string _configName = "MapImageService"; + protected IConfiguration m_configuration; + protected ILogger m_logger; + protected IComponentContext m_context; + + public string ConfigName { get; private set; } = _configName; - public IConfiguration Config { get; private set; } - public ILogger Logger { get; private set; } public IHttpServer HttpServer { get; private set; } public MapGetServiceConnector( IConfiguration config, - ILogger logger) + ILogger logger, + IComponentContext componentContext) { - Config = config; - Logger = logger; + m_configuration = config; + m_logger = logger; + m_context = componentContext; } public void Initialize(IHttpServer httpServer) { HttpServer = httpServer; - var serverConfig = Config.GetSection(ConfigName); + var serverConfig = m_configuration.GetSection(ConfigName); if (serverConfig.Exists() is false) throw new Exception($"No section {ConfigName} in config file"); @@ -71,10 +77,9 @@ public void Initialize(IHttpServer httpServer) if (string.IsNullOrWhiteSpace(gridService)) throw new Exception("No LocalServiceModule in config file"); - object[] args = new object[] { Config }; - m_MapService = ServerUtils.LoadPlugin(gridService, args); + m_MapService = m_context.ResolveNamed(gridService); - HttpServer.AddStreamHandler(new MapServerGetHandler(Logger, m_MapService)); + HttpServer.AddStreamHandler(new MapServerGetHandler(m_logger, m_MapService)); } } diff --git a/Source/OpenSim.Server.Handlers/Map/MapRemoveServerConnector.cs b/Source/OpenSim.Server.Handlers/Map/MapRemoveServerConnector.cs index e083937ff53..6c0325c23cc 100644 --- a/Source/OpenSim.Server.Handlers/Map/MapRemoveServerConnector.cs +++ b/Source/OpenSim.Server.Handlers/Map/MapRemoveServerConnector.cs @@ -41,6 +41,7 @@ using Microsoft.Extensions.Configuration; using Microsoft.Extensions.Logging; +using Autofac; namespace OpenSim.Server.Handlers.MapImage { @@ -50,25 +51,29 @@ public class MapRemoveServiceConnector : IServiceConnector private IGridService m_GridService; private static string _configName = "MapImageService"; + protected IConfiguration m_configuration; + protected ILogger m_logger; + protected IComponentContext m_context; + public string ConfigName { get; private set; } = _configName; - public IConfiguration Config { get; private set; } - public ILogger Logger { get; private set; } public IHttpServer HttpServer { get; private set; } public MapRemoveServiceConnector( IConfiguration config, - ILogger logger) + ILogger logger, + IComponentContext componentContext) { - Config = config; - Logger = logger; + m_configuration = config; + m_logger = logger; + m_context = componentContext; } public void Initialize(IHttpServer httpServer) { HttpServer = httpServer; - var serverConfig = Config.GetSection(ConfigName); + var serverConfig = m_configuration.GetSection(ConfigName); if (serverConfig.Exists() is false) throw new Exception($"No section {ConfigName} in config file"); @@ -76,21 +81,20 @@ public void Initialize(IHttpServer httpServer) if (string.IsNullOrEmpty(mapService)) throw new Exception("No LocalServiceModule in config file"); - object[] args = new object[] { Config }; - m_MapService = ServerUtils.LoadPlugin(mapService, args); + m_MapService = m_context.ResolveNamed(mapService); string gridService = serverConfig.GetValue("GridService", String.Empty); if (!string.IsNullOrEmpty(gridService)) - m_GridService = ServerUtils.LoadPlugin(gridService, args); + m_GridService = m_context.ResolveNamed(gridService); if (m_GridService != null) - Logger.LogInformation($"GridService check is ON"); + m_logger.LogInformation($"GridService check is ON"); else - Logger.LogInformation($"GridService check is OFF"); + m_logger.LogInformation($"GridService check is OFF"); - IServiceAuth auth = ServiceAuth.Create(Config, ConfigName); + IServiceAuth auth = ServiceAuth.Create(m_configuration, ConfigName); - HttpServer.AddSimpleStreamHandler(new MapServerRemoveHandler(Logger, m_MapService, m_GridService, auth)); + HttpServer.AddSimpleStreamHandler(new MapServerRemoveHandler(m_logger, m_MapService, m_GridService, auth)); } } diff --git a/Source/OpenSim.Server.Handlers/MuteList/MuteListServerConnector.cs b/Source/OpenSim.Server.Handlers/MuteList/MuteListServerConnector.cs index 34d9d682c9a..4ba70c76f0c 100644 --- a/Source/OpenSim.Server.Handlers/MuteList/MuteListServerConnector.cs +++ b/Source/OpenSim.Server.Handlers/MuteList/MuteListServerConnector.cs @@ -33,6 +33,7 @@ using Microsoft.Extensions.Configuration; using Microsoft.Extensions.Logging; +using Autofac; namespace OpenSim.Server.Handlers.GridUser { @@ -41,25 +42,29 @@ public class MuteListServiceConnector : IServiceConnector private IMuteListService m_MuteListService; private static string _ConfigName = "MuteListService"; - public string ConfigName { get; private set; } = _ConfigName; + protected IConfiguration m_configuration; + protected ILogger m_logger; + protected IComponentContext m_context; - public IConfiguration Config { get; private set; } - public ILogger Logger { get; private set; } + public string ConfigName { get; private set; } = _ConfigName; public IHttpServer HttpServer { get; private set; } public MuteListServiceConnector( IConfiguration config, - ILogger logger) + ILogger logger, + IComponentContext componentContext + ) { - Config = config; - Logger = Logger; + m_configuration = config; + m_logger = logger; + m_context = componentContext; } public void Initialize(IHttpServer httpServer) { HttpServer = httpServer; - var serverConfig = Config.GetSection(ConfigName); + var serverConfig = m_configuration.GetSection(ConfigName); if (serverConfig.Exists() is false) throw new Exception($"No section {ConfigName} in config file"); @@ -67,10 +72,9 @@ public void Initialize(IHttpServer httpServer) if (string.IsNullOrEmpty(service)) throw new Exception("LocalServiceModule not present in MuteListService config file MuteListService section"); - Object[] args = new Object[] { Config }; - m_MuteListService = ServerUtils.LoadPlugin(service, args); + m_MuteListService = m_context.ResolveNamed(service); - IServiceAuth auth = ServiceAuth.Create(Config, ConfigName); + IServiceAuth auth = ServiceAuth.Create(m_configuration, ConfigName); HttpServer.AddStreamHandler(new MuteListServerPostHandler(m_MuteListService, auth)); } diff --git a/Source/OpenSim.Server.Handlers/Presence/PresenceServerConnector.cs b/Source/OpenSim.Server.Handlers/Presence/PresenceServerConnector.cs index 2ff915c52c6..884000c5ef6 100644 --- a/Source/OpenSim.Server.Handlers/Presence/PresenceServerConnector.cs +++ b/Source/OpenSim.Server.Handlers/Presence/PresenceServerConnector.cs @@ -33,6 +33,7 @@ using Microsoft.Extensions.Configuration; using Microsoft.Extensions.Logging; +using Autofac; namespace OpenSim.Server.Handlers.Presence { @@ -40,28 +41,30 @@ public class PresenceServiceConnector : IServiceConnector { private IPresenceService m_PresenceService; private static string m_ConfigName = "PresenceService"; + + protected IConfiguration m_configuration; + protected ILogger m_logger; + protected IComponentContext m_context; public PresenceServiceConnector( IConfiguration config, - ILogger logger) + ILogger logger, + IComponentContext componentContext) { - Config = config; - Logger = logger; + m_configuration = config; + m_logger = logger; + m_context = componentContext; } public string ConfigName { get; private set; } = m_ConfigName; - public IConfiguration Config { get; private set; } - - public ILogger Logger { get; private set; } - public IHttpServer HttpServer { get; private set; } public void Initialize(IHttpServer httpServer) { HttpServer = httpServer; - var serverConfig = Config.GetSection(ConfigName); + var serverConfig = m_configuration.GetSection(ConfigName); if (serverConfig.Exists() is false) throw new Exception(String.Format("No section {0} in config file", ConfigName)); @@ -69,10 +72,9 @@ public void Initialize(IHttpServer httpServer) if (string.IsNullOrEmpty(gridService)) throw new Exception("No LocalServiceModule in config file"); - Object[] args = new Object[] { Config }; - m_PresenceService = ServerUtils.LoadPlugin(gridService, args); + m_PresenceService = m_context.ResolveNamed(gridService); - IServiceAuth auth = ServiceAuth.Create(Config, ConfigName); + IServiceAuth auth = ServiceAuth.Create(m_configuration, ConfigName); HttpServer.AddStreamHandler(new PresenceServerPostHandler(m_PresenceService, auth)); } diff --git a/Source/OpenSim.Server.Handlers/Profiles/UserProfilesConnector.cs b/Source/OpenSim.Server.Handlers/Profiles/UserProfilesConnector.cs index f16f4aa5c9a..38b98f488c0 100644 --- a/Source/OpenSim.Server.Handlers/Profiles/UserProfilesConnector.cs +++ b/Source/OpenSim.Server.Handlers/Profiles/UserProfilesConnector.cs @@ -31,6 +31,7 @@ using OpenSim.Server.Handlers.Base; using Microsoft.Extensions.Configuration; using Microsoft.Extensions.Logging; +using Autofac; namespace OpenSim.Server.Handlers.Profiles { @@ -38,29 +39,33 @@ public class UserProfilesConnector: IServiceConnector { private const string _ConfigName = "UserProfilesService"; + protected IConfiguration m_configuration; + protected ILogger m_logger; + protected IComponentContext m_context; + + public UserProfilesConnector( + IConfiguration config, + ILogger logger, + IComponentContext componentContext) + { + m_configuration = config; + m_logger = logger; + m_context = componentContext; + } + public IUserProfilesService ServiceModule { get; private set; } public bool Enabled { get; private set; } public string ConfigName { get; private set; } = _ConfigName; - public IConfiguration Config { get; private set; } - public ILogger Logger { get; private set; } public IHttpServer HttpServer { get; private set; } - public UserProfilesConnector( - IConfiguration config, - ILogger logger) - { - Config = config; - Logger = logger; - } - public void Initialize(IHttpServer httpServer) { HttpServer = httpServer; - var serverConfig = Config.GetSection(ConfigName); + var serverConfig = m_configuration.GetSection(ConfigName); if (serverConfig.Exists() is false) throw new Exception(String.Format("No section {0} in config file", ConfigName)); @@ -73,9 +78,7 @@ public void Initialize(IHttpServer httpServer) Enabled = true; string service = serverConfig.GetValue("LocalServiceModule", String.Empty); - - Object[] args = new Object[] { Config, ConfigName }; - ServiceModule = ServerUtils.LoadPlugin(service, args); + ServiceModule = m_context.ResolveNamed(service); JsonRpcProfileHandlers handler = new JsonRpcProfileHandlers(ServiceModule); diff --git a/Source/OpenSim.Server.Handlers/UserAccounts/UserAccountServerConnector.cs b/Source/OpenSim.Server.Handlers/UserAccounts/UserAccountServerConnector.cs index 4e6eb709421..e5a8bff6edb 100644 --- a/Source/OpenSim.Server.Handlers/UserAccounts/UserAccountServerConnector.cs +++ b/Source/OpenSim.Server.Handlers/UserAccounts/UserAccountServerConnector.cs @@ -34,6 +34,8 @@ using Microsoft.Extensions.Configuration; using Microsoft.Extensions.Logging; +using Autofac; + namespace OpenSim.Server.Handlers.UserAccounts { public class UserAccountServiceConnector : IServiceConnector @@ -41,26 +43,31 @@ public class UserAccountServiceConnector : IServiceConnector private IUserAccountService m_UserAccountService; private static string _ConfigName = "UserAccountService"; + protected IConfiguration m_configuration; + protected ILogger m_logger; + protected IComponentContext m_context; + + public UserAccountServiceConnector( IConfiguration config, - ILogger logger + ILogger logger, + IComponentContext componentContext ) { - Config = config; - Logger = logger; + m_configuration = config; + m_logger = logger; + m_context = componentContext; } public string ConfigName {get; private set; } = _ConfigName; - public IConfiguration Config {get; private set; } - public ILogger Logger {get; private set; } public IHttpServer HttpServer {get; private set; } public void Initialize(IHttpServer httpServer) { HttpServer = httpServer; - var serverConfig = Config.GetSection(ConfigName); + var serverConfig = m_configuration.GetSection(ConfigName); if (serverConfig.Exists() is false) throw new Exception($"No section {ConfigName} in config file"); @@ -68,10 +75,9 @@ public void Initialize(IHttpServer httpServer) if (string.IsNullOrEmpty(service)) throw new Exception("No LocalServiceModule in config file"); - Object[] args = new Object[] { Config }; - m_UserAccountService = ServerUtils.LoadPlugin(service, args); + m_UserAccountService = m_context.ResolveNamed(service); - IServiceAuth auth = ServiceAuth.Create(Config, ConfigName); + IServiceAuth auth = ServiceAuth.Create(m_configuration, ConfigName); HttpServer.AddStreamHandler(new UserAccountServerPostHandler(m_UserAccountService, serverConfig, auth)); } diff --git a/Source/OpenSim.Server.Handlers/UserAlias/UserAliasServiceConnector.cs b/Source/OpenSim.Server.Handlers/UserAlias/UserAliasServiceConnector.cs index 0b60a4b9293..cac8d28f448 100644 --- a/Source/OpenSim.Server.Handlers/UserAlias/UserAliasServiceConnector.cs +++ b/Source/OpenSim.Server.Handlers/UserAlias/UserAliasServiceConnector.cs @@ -33,6 +33,7 @@ using Microsoft.Extensions.Configuration; using Microsoft.Extensions.Logging; using OpenSim.Server.Handlers.Base; +using Autofac; namespace OpenSim.Server.Handlers.UserAlias { @@ -40,27 +41,31 @@ public class UserAliasServiceConnector : IServiceConnector { private IUserAliasService m_UserAliasService; private static string _ConfigName = "UserAliasService"; + + protected IConfiguration m_configuration; + protected ILogger m_logger; + protected IComponentContext m_context; public UserAliasServiceConnector( IConfiguration config, - ILogger logger + ILogger logger, + IComponentContext componentContext ) { - Config = config; - Logger = logger; + m_configuration = config; + m_logger = logger; + m_context = componentContext; } public string ConfigName {get; private set; } = _ConfigName; - public IConfiguration Config {get; private set; } - public ILogger Logger {get; private set; } public IHttpServer HttpServer {get; private set; } public void Initialize(IHttpServer httpServer) { HttpServer = httpServer; - var serverConfig = Config.GetSection(ConfigName); + var serverConfig = m_configuration.GetSection(ConfigName); if (serverConfig.Exists() is false) throw new Exception(String.Format("No section {0} in config file", ConfigName)); @@ -70,10 +75,10 @@ public void Initialize(IHttpServer httpServer) throw new Exception("No LocalServiceModule in config file"); } - Object[] args = new Object[] { Config }; - m_UserAliasService = ServerUtils.LoadPlugin(service, args); + m_UserAliasService = m_context.ResolveNamed(service); - IServiceAuth auth = ServiceAuth.Create(Config, ConfigName); + IServiceAuth auth = ServiceAuth.Create(m_configuration, ConfigName); + HttpServer.AddStreamHandler(new UserAliasServerPostHandler(m_UserAliasService, auth)); } }