Exemplo n.º 1
0
        public IServiceProvider ConfigureServices(IServiceCollection services)
        {
            services.Configure <CookiePolicyOptions>(options =>
            {
                options.CheckConsentNeeded    = context => true;
                options.MinimumSameSitePolicy = SameSiteMode.None;
            });

            var mvcBuilder = services.AddMvc()
                             .SetCompatibilityVersion(CompatibilityVersion.Version_2_2)
                             .ConfigureApplicationPartManager(LoadAspnetApplicationPlugins);

            var inheritedTypesRegistry = new InheritedTypesRegistry();

            LoadAllPlugins(services, inheritedTypesRegistry);

            // Allows the passing of JSON $type parameters (required for inherited types)
            mvcBuilder.AddJsonOptions(jsonOptions =>
            {
                jsonOptions.SerializerSettings.Converters.Add(new InheritedTypesJsonConverter(inheritedTypesRegistry));
            });

            services.Configure <DatabaseConnectionStrings>(Configuration.GetSection("ConnectionStrings"));

            services.AddSwaggerGen(c =>
                                   { c.SwaggerDoc("v1", new Info {
                    Title = "Toy Collector API", Version = "v1"
                }); }
                                   );

            return(CreateApplicationServiceProvider(services));
        }
Exemplo n.º 2
0
        private void LoadAllPlugins(IServiceCollection services, InheritedTypesRegistry inheritedTypesRegistry)
        {
            // Scan the startup path for DLL's and register their types
            var allDeployedDllFiles = Directory.GetFiles(
                Path.Combine(Environment.ContentRootPath, "bin"), "Axxes.ToyCollector.*.dll",
                SearchOption.AllDirectories);

            services.LoadConfiguredTypesFromFiles(inheritedTypesRegistry, allDeployedDllFiles);
        }
Exemplo n.º 3
0
 public InheritedTypesJsonConverter(InheritedTypesRegistry inheritedTypesRegistry)
 {
     _inheritedTypesRegistry = inheritedTypesRegistry;
 }