AXForum  
Вернуться   AXForum > Microsoft Dynamics AX > DAX Blogs
All
Забыли пароль?
Зарегистрироваться Правила Справка Пользователи Сообщения за день Поиск

 
 
Опции темы Поиск в этой теме Опции просмотра
Старый 03.01.2008, 10:06   #1  
Blog bot is offline
Blog bot
Участник
 
25,491 / 846 (79) +++++++
Регистрация: 28.10.2006
axStart: Making singleton objects from classes, DLL and CLR’s in AX.
Источник: http://axstart.spaces.live.com/Blog/...C0A0!213.entry
==============


It is possible in AX to have a global object in the memory that can be used any time. You create it one time on the client and all other x++call on that client will point to the first created object.
 
Official the SysGlobalCache is used for this purpose.  Code example infolog.chache.get(…), infolog.chache.set(…) or infolog.chache.isSet(…).  It should be better if the cached object act like a singleton
 
The trick is this: Registrate your permanent object in the class declaration of the Info class.
Next create a public method that returns the object. If the object was not created the object is also created in the get method.
 
Object getObject()
{
    if(!_object)
        _object = new Object();
    return _object;
}
 
This singleton concept can also be used for a CLR or DLL. First you declare it in the class declaration. Also declare the DLL Function.
 
DLL getDLL()
{
    if(!_dll)
        _dll = new DLL(‘DLL name’);
    return _dll;
}
Return type getDLLFunction()
{
    if(_dllFunctie)
    {
        _dllFunction = new DLLFunction(this.getDLL(),’functionName’);
        _dllFunction.return(…..);
        _dllFunction.arg(…..);
    }
    return _dllFunction. Call();
}
 
.Of course the CLR function is similar like the DLL
 
Now it is easier to work with it and an additional advantage is the performance of this code. it is realy fast.


Источник: http://axstart.spaces.live.com/Blog/...C0A0!213.entry
__________________
Расскажите о новых и интересных блогах по Microsoft Dynamics, напишите личное сообщение администратору.
Старый 03.01.2008, 20:55   #2  
EVGL is offline
EVGL
Banned
Соотечественники
Лучший по профессии 2017
Лучший по профессии 2015
Лучший по профессии 2014
 
4,445 / 3001 (0) ++++++++++
Регистрация: 09.07.2002
Адрес: Parndorf, AT
Подмастерье... Зачем курочить класс Info, если уже есть SysGlobalCache?

X++:
client server static TNNReelController getController(boolean _reset = false)
{
    TNNReelController   controller;
    SysGlobalCache      cache = classfactory.globalCache();
    ObjectIdent         ident;

    if (! _reset)
        ident = cache.get(classstr(TNNReelController), 0, null);

    if (! ident || ! ident.object())
    {
        controller = new TNNReelController();
        cache.set(classstr(TNNReelController), 0, new ObjectIdent(controller));
    }
    else
    {
        controller = ident.object();
    }

    return controller;
}
У меня, конечно, создается серверный синглетон, который НЕ держится все время в памяти, но идея та же.

Последний раз редактировалось EVGL; 03.01.2008 в 21:12.
За это сообщение автора поблагодарили: kashperuk (2).
Старый 04.01.2008, 00:48   #3  
kashperuk is offline
kashperuk
Участник
Аватар для kashperuk
MCBMSS
Соотечественники
Сотрудники Microsoft Dynamics
Лучший по профессии 2017
Лучший по профессии 2015
Лучший по профессии 2014
Лучший по профессии 2011
Лучший по профессии 2009
 
4,361 / 2084 (78) +++++++++
Регистрация: 30.05.2004
Адрес: Atlanta, GA, USA
А мне, в принципе, нравится этот автор.

Вот, кстати, он говорит, что обычно используется SysGlobalCache
Цитата:
Сообщение от axstart
Official the SysGlobalCache is used for this purpose.
Но спасибо за мнение, мне его всегда интересно слушать.
 


Ваши права в разделе
Вы не можете создавать новые темы
Вы не можете отвечать в темах
Вы не можете прикреплять вложения
Вы не можете редактировать свои сообщения

BB коды Вкл.
Смайлы Вкл.
[IMG] код Вкл.
HTML код Выкл.
Быстрый переход

Рейтинг@Mail.ru
Часовой пояс GMT +3, время: 02:31.
Powered by vBulletin® v3.8.5. Перевод: zCarot
Контактная информация, Реклама.