This example demonstrates how to implement a singleton - a class that can have a single instance that cannot be removed.
Implementation Details
For details, refer to the following help topic: How to: Implement a Singleton Business Object and Show its Detail View.
Files to Review
Does this example address your development requirements/objectives?
(you will be redirected to DevExpress.com to submit your response)
Example Code
C#using DevExpress.ExpressApp.Actions;
using DevExpress.ExpressApp.Editors;
using DevExpress.ExpressApp;
using DevExpress.Persistent.Base;
using SingletonSolution.Module.BusinessObjects;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using static System.Net.Mime.MediaTypeNames;
namespace SingletonSolution.Module.Controllers {
public class ShowSingletonController : WindowController {
public ShowSingletonController() {
this.TargetWindowType = WindowType.Main;
PopupWindowShowAction showSingletonAction =
new PopupWindowShowAction(this, "ShowSingleton", PredefinedCategory.View);
showSingletonAction.CustomizePopupWindowParams += showSingletonAction_CustomizePopupWindowParams;
}
private void showSingletonAction_CustomizePopupWindowParams(object sender, CustomizePopupWindowParamsEventArgs e) {
IObjectSpace objectSpace = Application.CreateObjectSpace(typeof(Singleton));
DetailView detailView = Application.CreateDetailView(objectSpace, objectSpace.GetObjects<Singleton>()[0]);
e.View = detailView;
}
}
}
C#using DevExpress.Persistent.BaseImpl;
using DevExpress.Persistent.BaseImpl.EF;
using DevExpress.Persistent.Validation;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace SingletonSolution.Module.BusinessObjects {
[RuleObjectExists("AnotherSingletonExists", DefaultContexts.Save, "True", InvertResult = true,
CustomMessageTemplate = "Another Singleton already exists.")]
[RuleCriteria("CannotDeleteSingleton", DefaultContexts.Delete, "False",
CustomMessageTemplate = "Cannot delete Singleton.")]
public class Singleton : BaseObject {
public virtual string Name { get; set; }
public virtual string Description { get; set; }
}
}