/// <summary> /// Configure IoC for 2sxc. If it's already configured, do nothing. /// </summary> public void Configure() { if (_alreadyConfigured) { return; } var appsCache = GetAppsCacheOverride(); Factory.ActivateNetCoreDi(services => { services .AddDnn(appsCache) .AddAdamWebApi <int, int>() .AddSxcWebApi() .AddSxcCore() .AddEav(); }); // now we should be able to instantiate registration of DB Factory.StaticBuild <IDbConfiguration>().ConnectionString = ConfigurationManager.ConnectionStrings["SiteSqlServer"].ConnectionString; var globalConfig = Factory.StaticBuild <IGlobalConfiguration>(); globalConfig.GlobalFolder = HostingEnvironment.MapPath(DnnConstants.SysFolderRootVirtual); // also register this because of a long DNN issue which was fixed, but we don't know if we're running in another version SharpZipLibRedirect.RegisterSharpZipLibRedirect(); ConfigurePolymorphResolvers(); _alreadyConfigured = true; }
public void ConfigureServices(IServiceCollection services) { // try to enable dynamic razor compiling - still WIP new StartUpRazorPages().ConfigureServices(services); // enable webapi - include all controllers in the Sxc.Mvc assembly services.AddControllers(options => { options.AllowEmptyInputInBodyModelBinding = true; }) // This is needed to preserve compatibility with previous api usage .AddNewtonsoftJson(options => { // this ensures that c# objects with Pascal-case keep that options.SerializerSettings.ContractResolver = new DefaultContractResolver(); Eav.ImportExport.Json.JsonSettings.Defaults(options.SerializerSettings); }); // enable use of UrlHelper for AbsolutePath services.AddSingleton <IActionContextAccessor, ActionContextAccessor>(); services.AddSingleton <IUrlHelperFactory, UrlHelperFactory>(); Factory.UseExistingServices(services); Factory.ActivateNetCoreDi(services2 => { services2 .AddSxcOqtane() .AddSxcRazor() .AddAdamWebApi <int, int>() .AddSxcWebApi() .AddSxcCore() .AddEav(); }); var sp = services.BuildServiceProvider(); // STV // var connectionString = Configuration.GetConnectionString("DefaultConnection"); // 2dm var connectionString = Configuration.GetConnectionString("SiteSqlServer"); sp.Build <IDbConfiguration>().ConnectionString = connectionString; var hostingEnvironment = sp.Build <IHostEnvironment>(); sp.Build <IGlobalConfiguration>().GlobalFolder = Path.Combine(hostingEnvironment.ContentRootPath, "wwwroot\\Modules\\ToSic.Sxc"); // 2sxc Oqtane blob services for Imageflow. services.AddImageflowOqtaneBlobService(); // 2sxc Oqtane dyncode app api. services.AddAppApi(); }
public Dictionary <string, object> CreateOrUpdate([FromUri] string contentType, [FromBody] Dictionary <string, object> newContentItem, [FromUri] int?id = null, [FromUri] string appPath = null) { Log.Add($"create or update type:{contentType}, id:{id}, path:{appPath}"); // if app-path specified, use that app, otherwise use from context var appId = GetAppIdFromPathOrContext_AndInitEavAndSerializer(appPath); // Check that this ID is actually of this content-type, // this throws an error if it's not the correct type var itm = id == null ? null : _entitiesController.GetEntityOrThrowError(contentType, id.Value); var perm = id == null ? Grants.Create : Grants.Update; PerformSecurityCheck(appId, contentType, perm, appPath == null ? Dnn.Module : null, App, itm); // Convert to case-insensitive dictionary just to be safe! newContentItem = new Dictionary <string, object>(newContentItem, StringComparer.OrdinalIgnoreCase); // Now create the cleaned up import-dictionary so we can create a new entity var cleanedNewItem = CreateEntityDictionary(contentType, newContentItem, appId); var userName = new DnnUser().IdentityToken; // try to create var currentApp = new App(new DnnTenant(PortalSettings), appId); //currentApp.InitData(false, new ValueCollectionProvider()); var publish = Factory.Resolve <IEnvironmentFactory>().PagePublisher(Log); currentApp.InitData(false, publish.IsEnabled(ActiveModule.ModuleID), Data.ConfigurationProvider); if (id == null) { currentApp.Data.Create(contentType, cleanedNewItem, userName); // Todo: try to return the newly created object return(null); } else { currentApp.Data.Update(id.Value, cleanedNewItem, userName); return(_entitiesController.Serializer.Prepare(currentApp.Data.List.One(id.Value))); } }
public void ConfigureServices(IServiceCollection services) { // try to enable dynamic razor compiling - still WIP new StartUpRazorPages().ConfigureServices(services); // enable webapi - include all controllers in the Sxc.Mvc assembly services.AddControllers(options => { options.AllowEmptyInputInBodyModelBinding = true; }) // This is needed to preserve compatibility with previous api usage .AddNewtonsoftJson(options => { // this ensures that c# objects with Pascal-case keep that options.SerializerSettings.ContractResolver = new DefaultContractResolver(); Eav.ImportExport.Json.JsonSettings.Defaults(options.SerializerSettings); }); //.PartManager.ApplicationParts.Add(new AssemblyPart(typeof(SxcMvc).Assembly)); // enable use of UrlHelper for AbsolutePath services.AddSingleton <IActionContextAccessor, ActionContextAccessor>(); services.AddSingleton <IUrlHelperFactory, UrlHelperFactory>(); Factory.UseExistingServices(services); Factory.ActivateNetCoreDi(services2 => { services2 .AddSxcOqtane() .AddSxcRazor() .AddAdamWebApi <int, int>() .AddSxcWebApi() .AddSxcCore() .AddEav(); }); var connectionString = Configuration.GetConnectionString("SiteSqlServer"); services.BuildServiceProvider().Build <IDbConfiguration>().ConnectionString = connectionString; }