Example #1
0
        public static TranslationPlugin ThisIsTheFactoryMethod(IPluginServiceProvider services)
        {
            var configFromHost = services.GetHostService <IConfiguration>();

            var hostService       = services.GetSharedHostService(typeof(ICurrentLanguageProvider));
            var hostServiceBridge = new CurrentLanguageProviderBridge(hostService);

            var dictionaryService = services.GetPluginService <IDictionaryService>();

            return(new TranslationPlugin(
                       configFromHost,    // This service is provided by the Prise.IntegrationTestsHost application and is registered as a Host Type
                       hostServiceBridge, // This service is provided by the Prise.IntegrationTestsHost application and is registered as a Remote Type
                       dictionaryService  // This service is provided by the plugin using the PluginBootstrapper
                       ));
        }
Example #2
0
        protected virtual object InjectFieldsWithServices(object remoteInstance, IPluginServiceProvider pluginServiceProvider, IEnumerable <PluginService> pluginServices)
        {
            foreach (var pluginService in pluginServices)
            {
                object serviceInstance = null;
                switch (pluginService.ProvidedBy)
                {
                case ProvidedBy.Host:
                    serviceInstance = pluginServiceProvider.GetHostService(pluginService.ServiceType);
                    break;

                case ProvidedBy.Plugin:
                    serviceInstance = pluginServiceProvider.GetPluginService(pluginService.ServiceType);
                    break;
                }

                try
                {
                    remoteInstance
                    .GetType()
                    .GetTypeInfo()
                    .DeclaredFields
                    .First(f => f.Name == pluginService.FieldName)
                    .SetValue(remoteInstance, serviceInstance);
                    continue;
                }
                catch (ArgumentException) { }

                if (pluginService.BridgeType == null)
                {
                    throw new PrisePluginException($"Field {pluginService.FieldName} could not be set, please consider using a PluginBridge.");
                }

                var bridgeConstructor = pluginService.BridgeType
                                        .GetConstructors(BindingFlags.Public | BindingFlags.Instance)
                                        .FirstOrDefault(c => c.GetParameters().Count() == 1 && c.GetParameters().First().ParameterType == typeof(object));

                if (bridgeConstructor == null)
                {
                    throw new PrisePluginException($"PluginBridge {pluginService.BridgeType.Name} must have a single public constructor with one parameter of type object.");
                }

                var bridgeInstance = bridgeConstructor.Invoke(new[] { serviceInstance });
                remoteInstance.GetType().GetTypeInfo().DeclaredFields.First(f => f.Name == pluginService.FieldName).SetValue(remoteInstance, bridgeInstance);
            }

            return(remoteInstance);
        }
Example #3
0
        protected virtual object InjectPluginFieldsWithServices(object remoteInstance,
                                                                IPluginServiceProvider pluginServiceProvider,
                                                                IEnumerable <PluginService> pluginServices)
        {
            foreach (var pluginService in pluginServices)
            {
                var    fieldName       = pluginService.FieldName;
                object serviceInstance = null;
                switch (pluginService.ProvidedBy)
                {
                case ProvidedBy.Host:
                    serviceInstance = pluginServiceProvider.GetHostService(pluginService.ServiceType);
                    break;

                case ProvidedBy.Plugin:
                    serviceInstance = pluginServiceProvider.GetPluginService(pluginService.ServiceType);
                    break;
                }

                if (TrySetField(remoteInstance, fieldName, serviceInstance))
                {
                    continue; // Field was set successfully, continueing
                }
                if (pluginService.ProxyType == null)
                {
                    throw new PluginActivationException($"Field {pluginService.FieldName} could not be set, please consider using a ReverseProxy.");
                }

                var reverseProxyCtor = GetReverseProxyConstructor(pluginService.ProxyType);
                if (reverseProxyCtor == null)
                {
                    throw new PluginActivationException($"ReverseProxy {pluginService.ProxyType.Name} must have a single public constructor with one parameter of type object.");
                }

                var reverseProxyInstance = AddToDisposables(reverseProxyCtor.Invoke(new[] { serviceInstance }));
                if (!TrySetField(remoteInstance, fieldName, reverseProxyInstance))
                {
                    throw new PluginActivationException($"Field {pluginService.FieldName} on Plugin could not be set.");
                }
            }

            return(remoteInstance);
        }
Example #4
0
        public static AuthenticatedDataService Factory(IPluginServiceProvider pluginServiceProvider)
        {
            var tokenService = pluginServiceProvider.GetPluginService <ITokenService>();

            return(new AuthenticatedDataService(tokenService));
        }