03.01.2008, 10:06 | #1 |
Участник
|
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 |
Banned
|
Подмастерье... Зачем курочить класс 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 |
Участник
|
А мне, в принципе, нравится этот автор.
Вот, кстати, он говорит, что обычно используется SysGlobalCache Цитата:
Сообщение от axstart
Official the SysGlobalCache is used for this purpose.
|
|