Вопрос

I am using XAF,I have an ApplicationSettings class,I create an object of this class in Updater.cs:

ApplicationSettings settings = ObjectSpace.FindObject<ApplicationSettings>(
    new BinaryOperator("Name", "DefaultSettings"));
if (settings == null) {
    settings = ObjectSpace.CreateObject<ApplicationSettings>();
    settings.Name = "DefaultSettings";
    // some code 
}

I want to get this object from another class, How can I do this?

Это было полезно?

Решение

I believe that your ApplicationSettings class should be a singleton. This way, you can easily access it from any part of your application. Refer to the example from the XAF documentation for more details on how to implement this. If you cannot use this option for some reason, you can always access your object using the FindObject method of the ObjectSpace or Session classes (as you already wrote above):

ApplicationSettings settings = ObjectSpace.FindObject( new BinaryOperator("Name", "DefaultSettings"));

Лицензировано под: CC-BY-SA с атрибуция
Не связан с StackOverflow
scroll top