Exemplo n.º 1
0
        /// <summary>
        /// Configure Entities in Plugin Modules
        /// </summary>
        /// <param name="modelBuilder"></param>
        protected virtual void ApplyEntitiesFromPlugins(ModelBuilder modelBuilder)
        {
            IAbpPlugInManager abpPlugInManager;

            if (IocManager.Instance.IsRegistered <IAbpPlugInManager>())
            {
                abpPlugInManager = IocManager.Instance.Resolve <IAbpPlugInManager>();
            }
            else // run by `dotnet ef`
            {
                var pluginRoot = WebContentDirectoryFinder.FindPluginsFolder();
                if (!Directory.Exists(pluginRoot))
                {
                    return;
                }
                abpPlugInManager = new AbpPlugInManager();
                abpPlugInManager.PlugInSources.AddFolder(pluginRoot);
            }

            try
            {
                var configurationTypes = abpPlugInManager.PlugInSources.GetAllAssemblies()
                                         .SelectMany(x => x.DefinedTypes
                                                     .Where(p => !p.IsAbstract && p.IsClass && p.GetInterface(nameof(IEntityConfiguration)) != null)
                                                     .Select(t => t.AsType()));
                foreach (var configuration in configurationTypes)
                {
                    try
                    {
                        (Activator.CreateInstance(configuration) as IEntityConfiguration).Configure(modelBuilder);
                    }
                    catch (Exception ex)
                    {
                        throw new Exception($"Can't configure entities of {configuration.FullName}", ex);
                    }
                }
            }
            catch (ReflectionTypeLoadException loadException)
            {
                throw new Exception(string.Join(" --> ", loadException.LoaderExceptions.Select(x => x.Message)),
                                    loadException);
            }
        }
Exemplo n.º 2
0
        public IServiceProvider ConfigureServices(IServiceCollection services)
        {
            services.AddSession(options =>
            {
                options.Cookie.HttpOnly = true;
            });

            // MVC
            services.AddMvc(options =>
            {
                options.Filters.Add(new CorsAuthorizationFilterFactory(_defaultCorsPolicyName));
            });

            IdentityRegistrar.Register(services);
            AuthConfigurer.Configure(services, _appConfiguration);

            // Configure CORS for angular2 UI
            services.AddCors(options =>
            {
                options.AddPolicy(_defaultCorsPolicyName, builder =>
                {
                    // App:CorsOrigins in appsettings.json can contain more than one address separated by comma.
                    builder
                    .WithOrigins(_appConfiguration["App:CorsOrigins"]
                                 .Split(",", StringSplitOptions.RemoveEmptyEntries)
                                 .Select(o => o.RemovePostFix("/"))
                                 .ToArray())
                    .SetPreflightMaxAge(TimeSpan.FromDays(1))
                    .AllowAnyHeader()
                    .WithMethods("OPTIONS", "GET", "POST", "PUT", "DELETE");
                });
            });

            // hangfire
            services.AddAbpHangfire(_appConfiguration.GetConnectionString("Default"));

#if DEBUG
            // Swagger - Enable this line and the related lines in Configure method to enable swagger UI
            services.AddSwaggerGen(options =>
            {
                options.SwaggerDoc("v1", new Info {
                    Title = "K9Abp API", Version = "v1"
                });
                options.DocInclusionPredicate((docName, description) => true);

                // Define the BearerAuth scheme that's in use
                options.AddSecurityDefinition("bearerAuth", new ApiKeyScheme
                {
                    Description = "JWT Authorization header using the Bearer scheme. Example: \"Authorization: Bearer {token}\"",
                    Name        = "Authorization",
                    In          = "header",
                    Type        = "apiKey"
                });
                // Assign scope requirements to operations based on AuthorizeAttribute
                options.OperationFilter <SecurityRequirementsOperationFilter>();

                // Set the comments path for the Swagger JSON and UI.
                var basePath  = AppDomain.CurrentDomain.BaseDirectory;
                var xmlForApi = Path.Combine(basePath, "K9Abp.Web.Core.xml");
                options.IncludeXmlComments(xmlForApi);
            });
#endif

            // Wechat
            services.AddSenpacService(_appConfiguration);

            // Configure Abp and Dependency Injection
            return(services.AddAbp <K9AbpWebHostModule>(options =>
            {
                options.IocManager.IocContainer.AddFacility <LoggingFacility>(
                    f => f.UseAbpNLog().WithConfig(Path.Combine("config", $"nlog.{_environment.EnvironmentName}.config")));
                var pluginsPath = WebContentDirectoryFinder.FindPluginsFolder();
                if (Directory.Exists(pluginsPath))
                {
                    options.PlugInSources.AddFolder(pluginsPath);
                }
            }));
        }