public static IServiceCollection AddPlugin <TType>(this IServiceCollection services, string dllPath = "") where TType : class
        {
            services.AddPlugin();

            if (string.IsNullOrWhiteSpace(dllPath))
            {
                var entryAssembly = Assembly.GetEntryAssembly();

                if (entryAssembly == null)
                {
                    dllPath = Environment.CurrentDirectory;
                }
                else
                {
                    dllPath = Path.GetDirectoryName(entryAssembly.Location);
                }
            }

            var typeFinderCriteria = TypeFinderCriteriaBuilder.Create()
                                     .AssignableTo(typeof(TType))
                                     .Build();

            var catalog = new FolderPluginProviders(dllPath, typeFinderCriteria);

            services.AddPluginCatalog(catalog);

            services.AddPluginType <TType>();

            return(services);
        }
示例#2
0
        // This method gets called by the runtime. Use this method to add services to the container.
        public void ConfigureServices(IServiceCollection services)
        {
            var folderPluginCatalog = new FolderPluginProviders(@"..\WebAPIPlugin\bin\debug\plugins", type =>
            {
                type.Implements <IOperator>();
            });

            services.AddPlugin()
            .AddPluginCatalog(folderPluginCatalog)
            .AddPluginType <IOperator>(configureDefault: option =>
            {
            });


            services.AddControllers();
            services.AddSwaggerGen(c =>
            {
                c.SwaggerDoc("v1", new OpenApiInfo {
                    Title = "WebAPI", Version = "v1"
                });
            });
        }