Hi,
I have a scenario where a majority of the data is being managed through an XAF application.
I have a second data access scenario where the user access some of the data (managed by the XAF application) through an MS Excel add-in.
I was wondering if it is possible to re-use the work done in creating the detail and list views to show them through this the add-in application?
Thanks,
Mark
How to reuse XAF Views and other standard module functionality in non-XAF apps, forms or controls
Answers approved by DevExpress Support
Hi Mark,
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 or YourSolutionName.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. If there are XAF dependencies in your ORM data model, it is still possible to use the eXpressApp Framework > Concepts > Data Manipulation and Business Logic > Access XAF Application Data in a non-XAF Application approach in your non-XAF app.
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:
Security:
How to: Use the Integrated Mode of the Security System in Non-XAF Applications
WinForms App
DevExtreme + ASP.NET Web API OData App
Console App
How to: Connect to the WCF Application Server from Non-XAF Applications
Reports:
How to: Use XAF Reports in a non-XAF Application
XAF Reports from Workflow Server
Audit:
How to reuse XAF Audit Trail module functionality in a non-XAF WinForms application
How to reuse XAF Audit Trail module functionality in a non-XAF ASP.NET application
Validation:
Xaf Model validation rules in non-XAF application and Rule validation and non-XAF application
File Attachments:
How to display XAF file attachments (e.g., a PDF document stored via FileData) in non XAF web site
WebForms:
Can I embed an XAF View in an IFRAME element placed in another web page?
WinForms:
Closing XAF Window closes entire application
General:
eXpressApp Framework > Concepts > Data Manipulation and Business Logic > Access XAF Application Data in a non-XAF Application
How to embed a ListView control with all the standard functionality into the navigation control
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));
}
}
}
Let me know if this helps.
Thanks
Dennis
I'm trying to use the example that you shared. Unfortunately, when creating everything you need, all data is protected. What should I do to be able to edit a new object?
Ps. I created an Add-In for Outlook to be able to add a button to the ribbon, and then after clicking the button, launch the XAF> application
C#public partial class Ribbon
{
XPObjectSpaceProvider directProvider = null;
ExpressAppWindowsFormsApplication theXafApplication = null;
private void Ribbon_Load(object sender, RibbonUIEventArgs e)
{
XpoTypesInfoHelper.GetXpoTypeInfoSource();
XafTypesInfo.Instance.RegisterEntity(typeof(IEDBaseObject));
directProvider = new XPObjectSpaceProvider(DevExpress.Xpo.DB.MSSqlConnectionProvider.GetConnectionString("DESKTOP-GU9BP9N\\SQLEXPRESS01", "sa", "!sql2017", "core"), null);
theXafApplication = new ExpressAppWindowsFormsApplication();
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.ConnectionString = DevExpress.Xpo.DB.MSSqlConnectionProvider.GetConnectionString("", "", "", "");
theXafApplication.Setup();
}
private void Button1_Click(object sender, RibbonControlEventArgs e)
{
IObjectSpace objectSpace = theXafApplication.CreateObjectSpace(typeof(IEDBaseObject));
IEDBaseObject obj = objectSpace.CreateObject<IEDBaseObject>();
obj.Sygnatura = "TEST";
//obj.Save();
//objectSpace.CommitChanges();
ShowViewParameters svp = new ShowViewParameters();
DetailView dv = theXafApplication.CreateDetailView(objectSpace, obj, true);
dv.ViewEditMode = DevExpress.ExpressApp.Editors.ViewEditMode.Edit;
svp.CreatedView = dv;
svp.TargetWindow = TargetWindow.NewWindow;
theXafApplication.ShowViewStrategy.ShowView(svp, new ShowViewSource(theXafApplication.CreateFrame(TemplateContext.View), null));
}
}
Hello Krzysztof,
I've created a separate ticket on your behalf (T739780: All data is protected when a XAF View is opened from the Outlook Add-In). It has been placed in our processing queue and will be answered shortly.
Hi Mark,
As far as I understand the task, you need to use our views outside XAF to show the required data. XAF list and detail views cannot exist without an XAF application. They are closely related to the application, application model, editors, etc. So, you cannot use the view's functionality in isolation from XAF application.
If I am mistaken, please provide me with more detailed explanation of the relation between XAF and your add-in. We will be happy to help you.
Thanks
Dennis
Hi Dennis,
Thank you for the information. I understand that the detail and list views are closely related to the XAF application. I understand that what I am asking for is not exactly the conventional use for XAF; however, I want to know the feasibility of it to see which path is better to pursue (re-create the necessary views in the other application and re-use the data layer or to also use the views from the XAF if possible).
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?
Thanks,
Mark