예제 #1
0
        public PluginLoadOptionsBuilder <T> WithDefaultOptions(string pluginPath = null, ServiceLifetime serviceLifetime = ServiceLifetime.Scoped)
        {
            if (String.IsNullOrEmpty(pluginPath))
            {
                pluginPath = Path.Join(GetLocalExecutionPath(), "Plugins");
            }

            this.priseServiceLifetime   = ServiceLifetime.Scoped;
            this.loggerType             = typeof(NullPluginLogger <T>);
            this.pluginPathProvider     = new DefaultPluginPathProvider <T>(pluginPath);
            this.dependencyPathProvider = new DependencyPathProvider <T>(pluginPath);
            this.cacheOptions           = CacheOptions <IPluginCache <T> > .ScopedPluginCache();

            this.runtimePlatformContext = new RuntimePlatformContext();
            this.ScanForAssemblies(composer =>
                                   composer.WithDefaultOptions <DefaultAssemblyScanner <T>, DefaultAssemblyScannerOptions <T> >());

            this.pluginAssemblyNameProvider      = new PluginAssemblyNameProvider <T>($"{typeof(T).Name}.dll");
            this.sharedServicesProvider          = new DefaultSharedServicesProvider <T>(this.hostServices, this.sharedServices);
            this.pluginActivationContextProvider = new DefaultPluginActivationContextProvider <T>();
            this.pluginTypesProvider             = new DefaultPluginTypesProvider <T>();
            this.activator    = new DefaultRemotePluginActivator <T>(this.sharedServicesProvider);
            this.proxyCreator = new PluginProxyCreator <T>();

            // Use System.Text.Json in 3.0
            this.parameterConverter  = new JsonSerializerParameterConverter();
            this.resultConverter     = new JsonSerializerResultConverter();
            this.assemblyLoaderType  = typeof(DefaultAssemblyLoaderWithNativeResolver <T>);
            this.assemblySelector    = new DefaultAssemblySelector <T>();
            this.assemblyLoadOptions = new DefaultAssemblyLoadOptions <T>(
                PluginPlatformVersion.Empty(),
                false,
                this.useCollectibleAssemblies,
                NativeDependencyLoadPreference.PreferInstalledRuntime);

            this.probingPathsProvider = new ProbingPathsProvider <T>();

            var hostTypesProvider = new HostTypesProvider <T>();

            hostTypesProvider.AddHostType(typeof(Prise.Plugin.PluginAttribute)); // Add the Prise.Infrastructure assembly to the host types
            hostTypesProvider.AddHostType(typeof(ServiceCollection));            // Adds the BuildServiceProvider assembly to the host types
            this.hostTypesProvider = hostTypesProvider;

            var remoteTypesProvider = new RemoteTypesProvider <T>();

            remoteTypesProvider.AddRemoteType(typeof(T)); // Add the contract to the remote types, so that we can have backwards compatibility
            this.remoteTypesProvider = remoteTypesProvider;

            this.pluginSelector               = new DefaultPluginSelector <T>();
            this.depsFileProviderType         = typeof(DefaultDepsFileProvider <T>);
            this.pluginDependencyResolverType = typeof(DefaultPluginDependencyResolver <T>);
            // Typically used for downloading and storing plugins from the network, but it could be useful for caching local plugins as well
            this.tempPathProviderType = typeof(UserProfileTempPathProvider <T>);

            this.nativeAssemblyUnloaderType = typeof(DefaultNativeAssemblyUnloader);
            this.hostFrameworkProviderType  = typeof(HostFrameworkProvider);

            return(this);
        }
예제 #2
0
 public PluginLoadOptionsBuilder <T> WithCachingOptions(ServiceLifetime serviceLifetime)
 {
     this.cacheOptions = new CacheOptions <IPluginCache <T> >(serviceLifetime);
     return(this);
 }
예제 #3
0
        public PluginLoadOptionsBuilder <T> WithSingletonCache()
        {
            this.cacheOptions = CacheOptions <IPluginCache <T> > .SingletonPluginCache();

            return(this);
        }