Ticket T302740
Visible to All Users

Xaf provide Singleton instance of a Domain Component for DetailView upon navigation

created 9 years ago

Hi,

I have a singleton domain component (non persistent). What I'm trying to do is to get XAF to open the corresponding detail view with the singleton instance upon navigating to the view (via the main navigation menu) .

Most of it is working, however I cannot figure out how to ensure the instance is passed to the DetailView when navigating.

I should mention that I have read through all articles, questions and examples about singletons and domain components I could find. Some of them are:
How to implement Singleton via Domain Components
https://www.devexpress.com/Support/Center/Question/Details/Q355782

How to: Implement a Singleton Business Object and Show its Detail View
https://documentation.devexpress.com/#eXpressAppFramework/CustomDocument112916

How to implement a singleton class
https://www.devexpress.com/Support/Center/Example/Details/E237

However all articles either describe using persistent business objects, or open up the singleton via an action, or creating a new object on navigation.

Basically, the solution example in Q355782 is what I'm looking for but I do not want to use an action, rather the navigation event.

Extracted code:

C#
public sealed partial class SolutionModule : ModuleBase { ... public override void Setup(XafApplication application) { if (!XafTypesInfo.IsInitialized) { XafTypesInfo.Instance.RegisterEntity("Singleton", typeof(ISingleton)); } base.Setup(application); } } [DomainComponent] public interface ISingleton { string Name { get; set; } string Description { get; set; } } [DomainLogic(typeof(ISingleton))] public class SingletonLogic { public static ISingleton GetInstance(IObjectSpace objectSpace) { ISingleton result = objectSpace.FindObject<ISingleton>(null); if (result == null) { result = objectSpace.CreateObject<ISingleton>(); result.Name = "My Singleton"; result.Description = "Empty"; } return result; } public static void OnDeleting(ISingleton instance) { throw new Exception("Cannot be deleted"); } } // I DO NOT WANT THIS public partial class ShowSingletonController : ViewController { public ShowSingletonController() { PopupWindowShowAction action = new PopupWindowShowAction(this, "ShowSingleton", DevExpress.Persistent.Base.PredefinedCategory.Unspecified); action.CustomizePopupWindowParams += new CustomizePopupWindowParamsEventHandler(action_CustomizePopupWindowParams); } void action_CustomizePopupWindowParams(object sender, CustomizePopupWindowParamsEventArgs e) { IObjectSpace objectSpace = Application.CreateObjectSpace(); e.View = Application.CreateDetailView(objectSpace, SingletonLogic.GetInstance(objectSpace)); } }

Answers approved by DevExpress Support

created 9 years ago (modified 9 years ago)

Hello Hans,

If you have a persistent domain component, you just need to follow the "Add an Item to the Navigation Control" section of the eXpressApp Framework > Task-Based Help > How to: Implement a Singleton Business Object and Show its Detail View article (which is valid for DC as well, because a domain component is actually a regular XPO class generated at runtime), while skipping the ShowSingletonController class.
If you have a non-persistent singleton, which is rather unusual, you will need to handle the eXpressApp Framework > DevExpress.ExpressApp > XafApplication > CustomProcessShortcut event. Refer to the eXpressApp Framework > Task-Based Help > How to: Display a Non-Persistent Object's Detail View from the Navigation article for examples.

P.S.
Are you sure you want to use Domain Components (DC) for your task? I see that you have recently started with DC and XAF and I wanted to inform you that this tech is supposed to be used by advanced XPO users in a limited set of scenarios.
I remember elaborating more on DC pre-requisites at Domain Components (DC) vs. XPO classes for a new project and I suggest you review that article before making further steps using the current approach as it can immediately get confusing if essential requirements for this tech are not met. I hope this helps. And do not hesitate to contact me in case of any questions.

    Show previous comments (5)
    Dennis Garavsky (DevExpress) 9 years ago

      Unfortunately, programming this task requires general ASP.NET knowledge and probably learning our ASP.NET controls, so I suggest you check out the corresponding documentation on these technologies before starting. You may find our search.devexpress.com tool helpful for searching our documentation and knowledge base.
      Finally, I hope that our ASP.NET Controls and MVC Extensions > ASP.NET WebForms Controls> Site Navigation and Layout > Form Layout component will help you save some time too.

        Yep, thanks for the tip. I'm already familiar with this so shouldn't be a problem. The issue is mostly that config values / ref data will be added quite frequently and redoing the layout (and I presume making sure all the models are merged for every update) will be a bit of a maintenance load.

        Dennis Garavsky (DevExpress) 9 years ago

          I see…

          Disclaimer: The information provided on DevExpress.com and affiliated web properties (including the DevExpress Support Center) is provided "as is" without warranty of any kind. Developer Express Inc disclaims all warranties, either express or implied, including the warranties of merchantability and fitness for a particular purpose. Please refer to the DevExpress.com Website Terms of Use for more information in this regard.

          Confidential Information: Developer Express Inc does not wish to receive, will not act to procure, nor will it solicit, confidential or proprietary materials and information from you through the DevExpress Support Center or its web properties. Any and all materials or information divulged during chats, email communications, online discussions, Support Center tickets, or made available to Developer Express Inc in any manner will be deemed NOT to be confidential by Developer Express Inc. Please refer to the DevExpress.com Website Terms of Use for more information in this regard.