Search This Blog
Thursday, July 14, 2016
How to reuse XAF Views and other standard module functionality in non-XAF apps
And one more update of the popular support topic, but quite advanced, though. Anyway, here we go:
Take special note that this is a specific and non-standard use-case scenario, which is not intentionally supported and tested by us internally. By default, many application modules rely on the XAF infrastructure and cannot be used outside it without special initialization or boilerplate code, which is usually created in the default XAF project templates created by the XAF Solution Wizard (see the YourSolutionName.Win/Program.xx orYourSolutionName.Web/Global.asax.xx files for more details). At the moment, most functionality of UI modules available to end-users is supposed to work in the client XAF WinForms, ASP.NET Web Forms and Mobile apps. For instance, you cannot have an arbitrary XAF DetailView embedded into your non-XAF ASP.NET MVC or WinForms app without much preparation (see the example below for more details) or at all with all the standard XAF functionality included.
Even though there are also non-visual XAF core components that can be reused in non-XAF apps with less effort (e.g., our security, audit and validation engines), they still require implementing custom-tailored solutions and a special initialization manually in your non-XAF app. Finally, since we do not test such scenarios internally, we do not guarantee normal operation of all XAF components in non-XAF apps. Depending on the module and target use scenario, there may be nuances and you must carefully test these scenarios or may probably be required to write additional code to get it working according to your business needs. For instance, since many standard modules (security, validation, reports, etc.) depend on the XafApplication.LoggedOn event or the activation of controllers for the main application window to perform their initialization, you may need to replicate the same circumstances in your non-XAF app if you want to make use of dependent functions. Also, if you're developing a Windows Forms app, it must be single-threaded (STA) by design, so you cannot easily invoke the standard XAF WinForms functionality in threads other than the main one.
On the other hand, it is important to note that in a well-designed and structured application, it is also not difficult to separate and reuse the ORM data model or business classes, which are normally not tied to the visual or UI parts. Very often, it is the best practice to have a single common or shared class library for your persistent classes, which may not have any XAF dependencies. This way, to use persistent objects in non-XAF applications and services, it is sufficient to add a reference to this shared assembly and then follow your ORM documentation (e.g., XPO) to learn more on how to set up database connection, create, query, delete persistent objects.
In general, we do not provide much guidelines and examples on using the pure XAF's components in non-XAF apps. We also may not be able to support you much if you have side effects in an unsupported and undocumented usage scenario. That said, if you wish to continue using XAF features in non-XAF apps, we recommend you use the approaches from the How can I debug DevExpress .NET source code using PDB files article and research the XAF source code to be able to diagnose possible errors on your own. In addition, you may find the following tickets and help articles helpful, because they describe the most typical scenarios asked for by our users:
In general, we do not provide much guidelines and examples on using the pure XAF's components in non-XAF apps. We also may not be able to support you much if you have side effects in an unsupported and undocumented usage scenario. That said, if you wish to continue using XAF features in non-XAF apps, we recommend you use the approaches from the How can I debug DevExpress .NET source code using PDB files article and research the XAF source code to be able to diagnose possible errors on your own. In addition, you may find the following tickets and help articles helpful, because they describe the most typical scenarios asked for by our users:
Concepts > Data Manipulation and Business Logic > Access XAF Application Data in a non-XAF Application
How to: Use Domain Components in non-XAF Applications
How to: Use the Integrated Mode of the Security System in Non-XAF Applications
How to: Connect to the WCF Application Server from Non-XAF Applications
How to: Use Domain Components in non-XAF Applications
eXpressApp Framework > Task-Based Help > How to: Use XAF Reports in a non-XAF Application
How to use XAF Audit Trail module outside XAF
How to use the XAF Audit Trail module in ASP.NET application
Xaf Model validation rules in non-XAF application and Rule validation and non-XAF application
How to display XAF file attachments (e.g., a PDF document stored via FileData) in non XAF web site
Can I embed an XAF View in an IFRAME element placed in another web page?
How to: Use Domain Components in non-XAF Applications
How to: Use the Integrated Mode of the Security System in Non-XAF Applications
How to: Connect to the WCF Application Server from Non-XAF Applications
How to: Use Domain Components in non-XAF Applications
eXpressApp Framework > Task-Based Help > How to: Use XAF Reports in a non-XAF Application
How to use XAF Audit Trail module outside XAF
How to use the XAF Audit Trail module in ASP.NET application
Xaf Model validation rules in non-XAF application and Rule validation and non-XAF application
How to display XAF file attachments (e.g., a PDF document stored via FileData) in non XAF web site
Can I embed an XAF View in an IFRAME element placed in another web page?
and more...
===============================================
===============================================
>>
Is it possible to instance the XAF Application (load the application model etc...) without having a main window show, and then to initiate the display of a detail or list view (that would appear in it's own window) via code? Can this be done from a class library as opposed to a Windows application?
<<
Yes, that is possible. For instance, to open XAF views from another non-XAF application, you need to create and setup an XafApplication instance in a similar manner as it is done in a typical XAF application. Please see the attached sample for more information. There, I create a regular windows forms application, which uses my application's library and XAF module to show a detail view for the business object. Note that you need to call the application's Setup method to configure the XAF application before using its functionality:
[C#]using System; using BusinessLogic; using System.Windows.Forms; using DevExpress.ExpressApp; using MyWinApplicationLibrary; using System.Configuration; using DevExpress.ExpressApp.Win; namespace WindowsApplication1 { public partial class Form1 : Form { WinSolutionWindowsFormsApplication theXafApplication = null; public Form1() { InitializeComponent(); //Dennis: NOTE: this basic XafApplication initialization is for demo purposes only. //It may be insufficient for all standard XAF scenarios and features like security, validation, Application Model, etc. //Refer to the https://www.devexpress.com/kb=Q94961 article to learn more. theXafApplication = new WinSolutionWindowsFormsApplication(); theXafApplication.SplashScreen = null; theXafApplication.ShowViewStrategy = new ShowInMultipleWindowsStrategy(theXafApplication); //theXafApplication.ConnectionString = ConfigurationManager.ConnectionStrings["XpoConnectionStringFromAppConfig"].ConnectionString; theXafApplication.ConnectionString = DevExpress.ExpressApp.Xpo.InMemoryDataStoreProvider.ConnectionString;//Dennis: For demo purposes only. theXafApplication.Setup(); } private void simpleButton1_Click(object sender, EventArgs e) { IObjectSpace objectSpace = theXafApplication.CreateObjectSpace(); ShowViewParameters svp = new ShowViewParameters(); svp.CreatedView = theXafApplication.CreateListView(objectSpace, typeof(DomainObject1), true); svp.TargetWindow = TargetWindow.NewWindow; theXafApplication.ShowViewStrategy.ShowView(svp, new ShowViewSource(theXafApplication.CreateFrame(TemplateContext.View), null)); } } }
Have questions? Please let me know in comments.
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment