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));
}
}