Current filter:
                                You should refresh the page.
                                • Anatol (DevExpress Support) 11.30.2018

                                  Hello Max,

                                  Your request is not quite clear to us. The new ASP.NET Core Data Service for SPA UI is already intended for working with json objects. Please clarify what example you would like to see in greater detail and describe your ultimate goal.

                                • Maximilian Kaya 12.02.2018

                                  Hello Anatol,
                                  I would like to see something like SPA UI Demo without any UI features, may be called  SPA API, which I want to use for queriyng xaf backend  from non xaf clients like curl, wget, python via bash, console.
                                  Such an example would be an easy start to understand and to use the new core data service for spa ui for me.
                                  I tried this by my own at this weekend but couldnt work it out, your help in this matter is greatly appreciated.


                                • Uriah (DevExpress Support) 12.03.2018

                                  Hello Max,

                                  Thank you for the clarification. We need additional time to answer your question. Please bear with us. We will get back to you as soon as possible.

                                1 Solution

                                Creation Date Importance Sort by

                                Hello Max,

                                Update for v19.2
                                We canceled the SPA UI. The DevExpress.ExpressApp.Spa assembly will not be available in v19.2. Please refer to the following tutorials to learn how to implement such a service without this assembly:
                                With Security - DevExtreme + ASP.NET Web API OData App
                                Without Security - ASP.NET Core web app with the DevExtreme template

                                For users who already use the SPA UI Data Service in their applications, we have published its sources in the following article: How to connect an existing XAF Mobile application to the new ASP.NET Core Data Service (CTP). Please see the upgrade steps for v19.2 there.

                                Old content
                                The New SPA UI for Web & Mobile is in the CTP state and its public API is not yet established. Methods, classes, interface names and files generated by our wizard will likely be changed in the future. Note that the below code samples are actual only for the current version: 18.2.4. However, the general concept will be the same in future versions.

                                The project created by the XAF application wizard is a regular ASP.NET Core Web application. You can use this project as a Web API service for your client applications. The DevExpress.ExpressApp.Spa assembly provides several controllers for the SPA UI client side (e.g., SpaApplicationController). However, their API is not documented and is intended specifically for the SPA UI. We recommend that you add your own Web API controllers for your client applications. The code snippet below demonstrates a controller that implements two methods to retrieve a collection of the Order object and retrieve a single object by key.

                                using System.Collections.Generic; using DevExpress.ExpressApp; using DevExpress.ExpressApp.Spa.AspNetCore; using DxSample.Module.BusinessObjects; using Microsoft.AspNetCore.Mvc; using System.Linq; using System; namespace DxSample.Controllers { [Route("api/[controller]")] [ApiController] public class OrdersController : ControllerBase { private readonly IXafApplicationProvider ApplicationProvider; public OrdersController(XafApplicationProvider applicationProvider) { this.ApplicationProvider = applicationProvider; } // GET api/orders [HttpGet] public ActionResult<IEnumerable<Order>> Get() { IObjectSpace os = ApplicationProvider.Application.CreateObjectSpace(typeof(Order)); return os.GetObjectsQuery<Order>().ToList(); } // GET api/Orders/5 [HttpGet("{id}")] public ActionResult<Order> Get(Guid id) { IObjectSpace os = ApplicationProvider.Application.CreateObjectSpace(typeof(Order)); return os.GetObjectByKey<Order>(id); } } }

                                Data modification operations (create, update, delete) are not implemented in this example. An XPO class cannot be bound to a controller method parameter, but it is possible to use other techniques to accept request data. You can use JObject or Dictionary class for this purpose:
                                Posting dictionary to web api in core
                                ASP.NET Core MVC : How to get raw JSON bound to a string without a type?

                                To save the request data to the database, create an Object  Space, create an object or load it from the database, modify or delete an object, and call the CommitChanges method.

                                An XAF SPA project contains the UI part that cannot be disabled. It is possible to create a new clean ASP.NET Core service using a standard ASP.NET Core Web Application project and add XAF functionality to it. To use an XAF object space in controllers, it is necessary to configure JSON options and register required services in the Startup.cs file. The required additional services include: IHttpContextAccessor, IXafApplicationProvider, IXafApplicationFactory. It is necessary to add an XafApplication descendant to the service project, and add a module containing persistent classes to the XafApplication.Modules collection.

                                I prepared a step by step instruction on how to create a read-only XAF-based ASP.NET Core Web API service.

                                1. Create a new ASP.NET Core Web Application. Make sure that you select the .NET Framework platform and the API project template on the configuration screen.
                                2. Add an XAF Module project that contains persistent class definitions. Add a reference to the Module project in the ASP.NET Core project.
                                3. Add references to the following assemblies:
                                 - DevExpress.ExpressApp.Spa.v18.2.dll
                                 - DevExpress.ExpressApp.Mobile.v18.2.dll
                                 - DevExpress.ExpressApp.v18.2.dll
                                 - DevExpress.ExpressApp.Xpo.v18.2.dll
                                 - DevExpress.Persistent.BaseImpl.v18.2.dll
                                 - DevExpress.Xpo.v18.2.dll
                                You can find assemblies in this folder: C:\Program Files (x86)\DevExpress 18.2\Components\Bin\Framework.
                                Also, add a reference to the standard System.Configuration assembly.
                                4. Add the SpaApplication.cs file and put the following code there.
                                using System; using System.Configuration; using DevExpress.ExpressApp.Spa; using DevExpress.ExpressApp; using DevExpress.ExpressApp.Xpo; namespace DxSample { public partial class DxSampleSpaApplication : SpaApplication { public DxSampleSpaApplication() { if (ConfigurationManager.ConnectionStrings["ConnectionString"] != null) { ConnectionString = ConfigurationManager.ConnectionStrings["ConnectionString"].ConnectionString; } Modules.Add(new Module.DxSampleModule()); // replace this with your own module name DatabaseVersionMismatch += DxSampleSpaApplication_DatabaseVersionMismatch; #if DEBUG if (System.Diagnostics.Debugger.IsAttached && CheckCompatibilityType == CheckCompatibilityType.DatabaseSchema) { DatabaseUpdateMode = DatabaseUpdateMode.UpdateDatabaseAlways; } #endif } private IXpoDataStoreProvider GetDataStoreProvider(string connectionString, System.Data.IDbConnection connection) { return XPObjectSpaceProvider.GetDataStoreProvider(connectionString, connection, true); } private void DxSampleSpaApplication_DatabaseVersionMismatch(object sender, DevExpress.ExpressApp.DatabaseVersionMismatchEventArgs e) { if (System.Diagnostics.Debugger.IsAttached) { e.Updater.Update(); e.Handled = true; } else { string message = "The application cannot connect to the specified database, " + "because the database doesn't exist, its version is older " + "than that of the application or its schema does not match " + "the ORM data model structure. To avoid this error, use one " + "of the solutions from the KB Article."; if (e.CompatibilityError != null && e.CompatibilityError.Exception != null) { message += "\r\n\r\nInner exception: " + e.CompatibilityError.Exception.Message; } throw new InvalidOperationException(message); } } protected override void CreateDefaultObjectSpaceProvider(CreateCustomObjectSpaceProviderEventArgs args) { args.ObjectSpaceProviders.Add(new XPObjectSpaceProvider(GetDataStoreProvider(args.ConnectionString, null), true)); args.ObjectSpaceProviders.Add(new NonPersistentObjectSpaceProvider(TypesInfo, null)); } } }
                                5. Open the Startup.cs file in the ASP.NET project and modify it as shown below.
                                using DevExpress.ExpressApp; using DevExpress.ExpressApp.Mobile; using DevExpress.ExpressApp.Spa.AspNetCore; using DevExpress.Persistent.Base; using Microsoft.AspNetCore.Builder; using Microsoft.AspNetCore.Hosting; using Microsoft.AspNetCore.Http; using Microsoft.AspNetCore.Mvc; using Microsoft.Extensions.Configuration; using Microsoft.Extensions.DependencyInjection; using Newtonsoft.Json; namespace DxSample { public class Startup { public Startup(IConfiguration configuration) { Configuration = configuration; } public IConfiguration Configuration { get; } public void ConfigureServices(IServiceCollection services) { services.AddMvc() .SetCompatibilityVersion(CompatibilityVersion.Version_2_1) .AddJsonOptions(s => { s.SerializerSettings.ReferenceLoopHandling = ReferenceLoopHandling.Ignore; s.SerializerSettings.ContractResolver = new TypesInfoContractResolver(); }); services.AddSingleton<IHttpContextAccessor, HttpContextAccessor>(); services.AddScoped<IXafApplicationProvider, XafApplicationProvider>(); services.AddScoped<IXafApplicationFactory, XafApplicationFactory<DxSampleSpaApplication>>(); } public void Configure(IApplicationBuilder app, IHostingEnvironment env) { if (env.IsDevelopment()) { app.UseDeveloperExceptionPage(); } app.UseMvc(); HttpContextValueManager.HttpContextAccessor = app.ApplicationServices.GetRequiredService<IHttpContextAccessor>(); ValueManager.ValueManagerType = typeof(HttpContextValueManager<>).GetGenericTypeDefinition(); } } }
                                6. Configure the database connection string in the app.config file.
                                <connectionStrings> <add name="ConnectionString" connectionString="data source=.;initial catalog=T695895;integrated security=sspi"/> </connectionStrings>

                                Now, you can create Controllers to implement API methods. Use the example provided at the beginning of this article. XAF SPA projects currently do not support XAF Security System. However, the code provided in the example should inherently take advantage of the Security System when it will be implemented in XAF SPA projects.

                                Show all comments
                                • Dennis (DevExpress) 03.06.2019

                                  Max, can we make this ticket public, please?

                                • Maximilian Kaya 03.06.2019

                                  sure, please go ahead Dennis

                                • Dennis (DevExpress) 03.06.2019

                                  Thank you!

                                • Jacek Kosiński 04.29.2019

                                  How to extend this example to support XAF security ?

                                • Dennis (DevExpress) 04.30.2019

                                  @Customer73848: I've answered you in a separate ticket: T737099: ASP.NET Core Data Service for SPA UI with security.

                                • Maximilian Kaya 08.27.2019

                                  any hints/updates/replacement using 19.2.1 preview on this?

                                • Dennis (DevExpress) 08.28.2019

                                  Hello Maximilian,

                                  We canceled the SPA UI and DevExpress.ExpressApp.Spa will not be available in v19.2. We are working on a migration path for a few users who integrated this solution into their Mobile UI (Maintenance Mode) projects. It is likely that by the v19.2 release time we will provide an updated sample where all required data service code from DevExpress.ExpressApp.Spa will be inside the sample itself. Right away, you can switch to the original Mobile UI data service, which is not based on ASP.NET Core.

                                  If you have any specific usage of this ASP.NET Core service in your projects, please elaborate on this.

                                • Dennis (DevExpress) 08.28.2019

                                  I also forgot to mention that we’re doing our best to explain the XAF security system and how it can be used in non-XAF .NET apps powered by XPO. Please check our new ASP.NET Core Web API/OData v4 + DevExtreme sample & tutorial.

                                • Anatol (DevExpress Support) 09.03.2019

                                  We have updated the article. Please see solutions recommended for version 19.2 in the Update for v19.2 section.