26

Re: Context transmission through set of abstraction layers of application

Hello, Sinix, you wrote: S> Well and it already the general for all DI-frejmvorkov a problem. The most simple method - is used only documentary dependences which are issued in the form of extension-methods, they should be accessible always. For exotic or we write tests + debug , or let to myself falls is it will be possible better, than start in  the unchecked code. Yes here especially that also does not help, as thanks to the transparent dragging of a context through layers, somewhere level on 5, this will be pulled most  type Context. GetLogger (), and three levels above somebody imports a component and pulls a tail, without guessing at all, what hardly there is any binding to a context more deeply.

27

Re: Context transmission through set of abstraction layers of application

Hello, LWhisper, you wrote: LW> Yes here especially that also does not help, as thanks to the transparent dragging of a context through layers, somewhere level on 5, this will be pulled most  type Context. GetLogger (), and three levels above somebody imports a component and pulls a tail, without guessing at all, what hardly there is any binding to a context more deeply. In sense? Documentary dependences should be accessible always. Them actually for this purpose also document. Well and the transparent dragging in practice is absolutely optional.

28

Re: Context transmission through set of abstraction layers of application

Hello, LWhisper, you wrote: LW> CallContext - a smart piece! Nasty it is a piece. It is necessary to use at total absence of alternatives LW> And is any best practices on development of business logic with usage of contexts? How to inform to readers-writers of the code, what here this piece depends on the same ILogger which is necessary for initializing and if it not to make you will fail out of the blue with NotInitializedException? The principal recommendation - not to import dynamics there where it is possible to manage a statics. Especially it is fans DI of containers concerns.... <<RSDN@Home 1.0.0 alpha 5 rev. 0 on Windows 8 6.2.9200.0>>

29

Re: Context transmission through set of abstraction layers of application

30

Re: Context transmission through set of abstraction layers of application

31

Re: Context transmission through set of abstraction layers of application

LW> In this connection a question - what to do?  unfortunately at you a heap of questions. Different. LW> here both Id sessions, and Id the current task, and a user id Here it is necessary to separate flies from cutlets. A context or State  given are cutlets. Classes   are flies. These are two absolutely different essences. With  it is possible to arrive on a miscellaneous if this  it is necessary  with itself and to store in storage that as a matter of fact variants only two. To do it it is explicit or it is not explicit. Not explicit - to transfer it as that is implicit Or through TLS (ThreadStatic) or is twice implicit - to create Child the container in which will register Singleton which to return state either completely or in parts. Child it is good that that the code which uses  as a matter of fact knows nothing about its lifetime. It it will be simple to depend on the interface which allows to work with  and all. And a minus of this approach in that that as a matter of fact it hides in itself(himself) a certain magic. I.e. Where that forms certain child the container in which there is a certain class registered by a certain method. And God forbid who that asks this interface for the parent container. Implicit transmission of a context through ThreadStatic is problems with the asynchronous code (async/await). As the candidate solution of problems with ThreadStatic and async/await can be LogicalCallContext. In 4.5 it is able "" between flows. - stupidly transfers other, stupid and simple variant  in each call of each method to which it can it is required. From minuses personally: Personally I see a couple 1. We we will often transfer "the superfluous data", for example, in a class it is necessary to hand over the information only about the user and the given sessions and others are not necessary. Partially this problem can be solved breaking a context on some small abstract classes or interfaces and one successor.  to whom all context is necessary will accept in parameters the successor, to whom parts - parts. 2. It can sounds strange - but it is exact not a fashionable method, it too simple, it does not give to you , to show you knowledge of aspects of operation of containers ... It looks . From pluses: 1. It is super simply and absolutely precisely minimizes various  problems with other variants   the container, ThreadStatic or LogicalCallContext. 2. Explicit it is always better Implicit it is an axiom. Having a context explicitly its usage it is possible to trace easily on the code. 3. It is very cheap from the point of view of productivity. Personally I now selected explicit transmission of a context. And the context as can implement the interface which can accept classes   in the methods . Note they will not accept this interface in the designer namely in methods and it is normal, for a context it state, the data and they in an ideal should float through a stack.

32

Re: Context transmission through set of abstraction layers of application

Hello, LWhisper, you wrote: LW> we Take, for an example, . To throw out all this  and to fasten NLog + Sumologic (or alternatives to taste).   in each class of private static variable.

33

Re: Context transmission through set of abstraction layers of application

Hello, Sinix, you wrote: S> At  just one of problems - as this container on all call chain to drag. There are any ideas? It does not need to be dragged anywhere. It is enough to use the mechanism of events - the component will have a dial-up of relevant events, and  on them will be signed.  on them it will be signed - does not mean at all that the code  should be touched. There will be a separate listener of events who will listen to the necessary events and to replenish a broad gull, using .

34

Re: Context transmission through set of abstraction layers of application

Hello, LWhisper, you wrote: LW> In this connection a question - what to do? LW> is certain  applications which, being torn through set of abstraction layers, all leaves more deeply in a jungle of internal-assemblages and in passing acquires parameters-dependences, to the lower points of the falling coming to that to 28 arguments in the designer of the next class without which he cannot live. One of OOP major principles: the bulb twists itself in a lamp itself. LW> here both Id sessions, and Id the current task, and a user id, and  and still what the hell, on the person awful,  inside. As the component doing real operation, depends on identifiers and journalizing (many here very narrowly understand terms, therefore I specify: it is sacral  in Russian)? To fulfill operation, the instruction, instead of log is necessary - it is logical? Operation depends on the instruction, log from an operation state. Dependence in your application other - log depends on components, instead of they from it. If it to realize, it becomes easier to untangle a ball of dependences. How to log to learn about a current state of components and to replenish itself? How to components to inform on the state in the independent image?  NET there is a mechanism of events - he solves both questions a simple method. It is not necessary to ignore it. LW> It would be desirable to throw out it in any easily accessible (both in respect of the code, and in respect of performance) a context with which it will be easy to communicate. LW> for given by that context the DB, thanks to that it only one access is carried out through  (sometime it is mandatory shoots - _-) appears. LW> And here for all remaining it misses, and these dependences per aspera ad astra are pulled. LW> we Take, for an example, . LW> application Here is started and quickly starts to write a broad gull. The broad gull name goes down in arguments a command of a line. LW> Okej, is difficult to refuse it (though and it is possible) but while it is tolerant. LW> there is an authentification of the user. Now the broad gull is written already to the directory of this hapless user. LW> the user executes some command, the broad gull is written all to the same folder, but already in a file with a name of an executed command. LW> the command begins  and works with different computers in a network. Each task starts to write a broad gull to a file with a name mentioned above a command + computer name. This listing of events to which the log should react (). It is necessary to think over the mechanism of the publication of events and a subscription to them. Default events.NET, the homebrew manager of events is already details. LW> in process, we start to use more low-level interfaces which too write a broad gull and not at all do not know anything neither about users, nor about commands, about hosts. But thus too want to write to a broad gull a current state and  errors, leaving on  if the grid blinked, but still there is a chance to receive the response from the remote machine. And to write that broad gulls it is necessary in the same files with a name of a command, a host, in a folder of the user. There are ThreadLocal-collections  through which transit all calls. The same principle, log receives entering events and itself solves where they will be saved. All smart logic of crushing of log will be concentrated in one place, any contexts. LW> but low-level components too not a bast  and besides  top-level, pull asynchronous methods on lower which are at all fulfilled in a casual flow from a pool and in turn too pull even more low-level components which still want to write broad gulls to the same files, as far  their component. So it is necessary to drag through all layers  and to register it in a static ThreadLocal-collection from the previous series. Components should publish events, to log them to listen. LW> some time I smother torment thoughts about Dependeny Injection. But in the company already there was an unsuccessful experience of implementation of this piece (about which (oh) I neither a dream, nor spirit), ended with cutting out of this with a considerable quantity . In general, did not get accustomed, yes it and is clear - lifetime and the order of initialization of objects were misunderstood from a word absolutely, and frequently objects which they did not ask were returned to people, and have been registered at all do not understand whom, when and for what purpose. In general, all is bad, and besides because of unreasoned architecture,  on a knee that though somehow worked in style write-only. Implementation of dependences - a short-term stage at program start. It here it is simple at anything.

35

Re: Context transmission through set of abstraction layers of application

LW> Here both Id sessions, and Id the current task, and a user id, and  and still what the hell, on the person awful,  inside. Well roughly speaking at you a problem with that that in designers you transfer a piece ,  in salad? myCtor (int userId, int sessionId, int taskid) in stupid to tear dependence if the task wants to write down by all means in the broad gull , , start up suffers class MyTask {Session session; void WriteLog (string);}; class Session {User user; void WriteLog (string);} myCtor (MyTask) LW> In process, we start to use more low-level interfaces which too write a broad gull and not at all do not know anything neither about users, nor about commands, about hosts. Here it is the key moment in all epopee.  session, the user, and an other crap is not necessary to the majority of the code. If critically to look, it and above in most cases was not necessary. class MyLowLevelContraption {MyLowLevelContraption (int userId, int sessionId, int taskid, IMyLogger);//here the such should not be MyLowLevelContraption (MyTask);//and such too though it is already better MyLowLevelContraption (IMyLogger);//and even such it is not necessary to do.....} I would rivet approximately so class MyLowLevelContraption {MyLowLevelContraption (); delegate void LogEventHandler (string); event LogEventHandler WriteLog;.....}//dependence  outside new MyLowLevelContraption () {WriteLog + = currentContext. WriteLog;}

36

Re: Context transmission through set of abstraction layers of application

Hello, Vladek, you wrote: S>> At  just one of problems - as this container on all call chain to drag. There are any ideas? V> it does not need to be dragged anywhere. It is enough to use the mechanism of events - the component will have a dial-up of relevant events, and  on them will be signed. Such councils in 100 % of cases mean that the person either did not use , or got used to give advice, without reflecting on consequences. If similar it is offered absolutely seriously on the real project and the person does not understand hints, is treated simply. We arrive in the same way, as well as with the useful sentence. The real code with pair hundreds calls  (it very little) from which half - in static-methods, and third more - in await | iterators is given and it is offered to estimate expenditures of labor on transfer into model of events. Also to paint possible jambs (if does not name memory leak / a call of event handlers in the "wrong" order and mutual side-effects from subscribers - one more minus in the sentence budget) and cost of measures on their correction. If following the results of the person did not like, further variants full. Or we place in a command with a good lead on conversion training, or it is spanned on the project where from tireless activity there will be a favor, or we leave good recommendations, let competitors take. The person capable for the love of the abstract ideas to drag of them in the project, as a result does much harm so any conscious diversion by children's morning performance seems.

37

Re: Context transmission through set of abstraction layers of application

Hello, Sinix, you wrote: S> Hello, Vladek, you wrote: S>>> At  just one of problems - as this container on all call chain to drag. There are any ideas? V>> it does not need to be dragged anywhere. It is enough to use the mechanism of events - the component will have a dial-up of relevant events, and  on them will be signed. S> such councils in 100 % of cases mean that the person either did not use , or got used to give advice, without reflecting on consequences. S> if similar it is offered absolutely seriously on the real project and the person does not understand hints, is treated simply. We arrive in the same way, as well as with the useful sentence. The real code with pair hundreds calls  (it very little) from which half - in static-methods, and third more - in await | iterators is given and it is offered to estimate expenditures of labor on transfer into model of events. Also to paint possible jambs (if does not name memory leak / a call of event handlers in the "wrong" order and mutual side-effects from subscribers - one more minus in the sentence budget) and cost of measures on their correction. You work, itself paint jambs. It is desirable with examples. What to me to sense from your arrogance?

38

Re: Context transmission through set of abstraction layers of application

Hello, Vladek, you wrote: V> You work, itself paint jambs. It is desirable with examples. What to me to sense from your arrogance? Well so it not arrogance,  standard response to recommendations in style "to the mouse become hedgehogs". Not, seriously, well as it is possible to advise  nonsense? The most elementary example (the real code, names clear business are changed): static async Task DoAsync (string uri, ILogger logger) {try {await DoAsyncCore (uri);} catch (Exception ex) {logger.Log ("Do async failed, bla-bla-bla", ex); throw;}} Try to represent the same on events. Only  not that was, and as though you wrote for the real code which in  goes.

39

Re: Context transmission through set of abstraction layers of application

Hello, Sinix, you wrote: S> Try to represent the same on events. Only  not that was, and as though you wrote for the real code which in  goes. Here the Author: rm822 Date: 31.07 01:46 without me gave a variant. In  the code which will not block up log with garbage goes. In case of problems from log record of actions of the user (commands and requests) is necessary to me and any data on an output from the program (the minimum runtime of operation and the call in case of an exceptional situation flew down) then to play back a problem. That is, internal state of the program not too important and consequently the log will influence not so strongly interfaces of components. The internal state of the program not important if it is determined is means, if I admitted a situation when I can play back a problem only in  - I did not complete the operation and should not to hammer in broad gulls garbage all the same to receive any representation that there happens, and to complete operation that the program behaved stablly, irrespective of an external environment. We return to a method from an example. In it there will be no log generally. Input parameters (a command, request) if they go from the user or any external event (message queue, for example), will be placed in log at the moment of their appearance, to a method call. The exception information returns itself upwards on a stack and too will be placed in log in the fullness of time (normally in the same place where handling of request from the user / an external surrounding began). var commandName = command. GetType ().Name + "("+ command. GetHashCode () +")"; var stopwatch = new Stopwatch (); try {Debug. WriteLine ("{0} executing {1}", this.dispatcherName, commandName); Debug. WriteLine ("{0} {1} is {2}", this.dispatcherName, commandName, command. ToString ()); stopwatch. Start (); await this.dispatcher. ExecuteAsync (command);} catch (Exception x) {Debug. WriteLine ("{0} caught error: {1}", this.dispatcherName, x); throw;} finally {stopwatch. Stop (); Debug. WriteLine ("{0} executed {1} ({2} ms)", this.dispatcherName, commandName, stopwatch. ElapsedMilliseconds);} Here the manager dispatcher - is engaged in command transmission to the necessary output agent. Here this here the code - just the same manager-wrapper with log (in this case it is a normal debug output). Output agents of commands too can have the logs working similarly. The code actually performing operation, is not littered by calls of log or calls to any contexts.

40

Re: Context transmission through set of abstraction layers of application

Hello, Vladek, you wrote: V> In  the code which will not block up log with garbage goes. V> we Return to a method from an example. In it there will be no log generally. I speak - you do not use  what to consider? What  "Debug. WriteLine"? You in  on the live server will palm off debug builds??? Or at you any situation always locally is played back, without a knot on user data? V> if I admitted a situation when I can play back a problem only in  - I did not complete the operation and should not to hammer in broad gulls garbage all the same to receive any representation that there happens, and to complete operation that the program behaved stablly, irrespective of an external environment. Ugu-ugu. It is you to companions to implementers tell in a situation when the person for 10k kilometers from you and at it comes to an end a working day, you have less half of day on to repair system (i.e. Minimum of hours 5 - not yours, and QA and implementers), you cannot connect a remote debugger for the rights to the server at you are not present, and do not receive, for the tolerance should be made out still. Absolutely typical situation in any more or less large product, a minimum of times in a quarter meets. Good luck what to tell. It is treated not less standardly, the type instruction we "tick off" all disappeared,  ", we play back, we leave a contact information, we wait for a call/letter". If at people a paranoia and access to the Internet it is superimposed, it is necessary to send still files with trace totals to the specified address, yes. V> we Return to a method from an example. V> this.dispatcher Well, i.e. the simple static-method suddenly becomes a member of a class and starts to row up dependences which in the original were easy transferred in parameters. Thus the initial task - to throw off the error report in specific , instead of in the general log - is not solved. Well and events for the sake of which we also started to invent a bicycle, too suddenly are not present. And it we do that __ testing / attending, missed nothing?

41

Re: Context transmission through set of abstraction layers of application

Hello, Sinix, you wrote: S> Hello, Vladek, you wrote: V>> In  the code which will not block up log with garbage goes. V>> we Return to a method from an example. In it there will be no log generally. S> I speak - you do not use  what to consider? S> what  "Debug. WriteLine"? You in  on the live server will palm off debug builds??? Or at you any situation always locally is played back, without a knot on user data? User data will be in log - record of its actions. And further it is already possible to analyze locally that happens to the program after input of this data. If there there is a DB which is necessary for problem playback it is possible to be connected to it in a read mode or to use a copy. V>> if I admitted a situation when I can play back a problem only in  - I did not complete the operation and should not to hammer in broad gulls garbage all the same to receive any representation that there happens, and to complete operation that the program behaved stablly, irrespective of an external environment. S> Ugu-ugu. It is you to companions to implementers tell in a situation when the person for 10k kilometers from you and at it comes to an end a working day, you have less half of day on to repair system (i.e. a minimum of hours 5 - not yours, and QA and implementers), you cannot connect a remote debugger for the rights to the server at you are not present, and do not receive, for the tolerance should be made out still. Absolutely typical situation in any more or less large product, a minimum of times in a quarter meets. S> good luck what to tell. It to you good luck, such did not happen for a long time to me. Any specific example from the experience here at anything. Really, what sense to consider jambs in the operation? Jambs should be corrected as it is necessary, time they happened. We consider as not to admit jambs instead of as them to correct. If the jamb becomes a typical situation - it is necessary to change something in conservatory. The Brut-swagger does not help. S> It is treated not less standardly, the type instruction we "tick off" all disappeared,  ", we play back, we leave a contact information, we wait for a call/letter". If at people a paranoia and access to the Internet it is superimposed, it is necessary to send still files with trace totals to the specified address, yes. V>> we Return to a method from an example. V>> this.dispatcher S> Well, i.e. the simple static-method suddenly becomes a member of a class and starts to row up dependences which in the original were easy transferred in parameters. S> thus the initial task - to throw off the error report in specific , instead of in the general log - it is not solved. Well and events for the sake of which we also started to invent a bicycle, too suddenly are not present. The example with events was in other post, I gave the reference. My code - an example of my approach (without events). With events there are no special problems - there is remarkable library Rx which helps to cope with redirection of events on logs. Even easier to have the separate listener on each class of components. S> and it we do that __ testing / attending, missed nothing? It is necessary to ask it the author of the first post, what for to it such system of dens. We suggest simple methods to solve a problem without brute force engaging.

42

Re: Context transmission through set of abstraction layers of application

Hello, Vladek, you wrote: V> User data will be in log - record of its actions. And further it is already possible to analyze locally that happens to the program after input of this data. If there there is a DB which is necessary for problem playback it is possible to be connected to it in a read mode or to use a copy. As they in log will be, if you only for debug builds write the information? Bases do not give to you to 90 % of cases under no circumstances. - separate requests allow to span a maximum to the system administrator (only select, certainly), it checks up them, fulfills and spans reversely result (thus still, happens, is admitted to check only presence of records/values in fields but not to pull out the data). Contents of dens are in the same way coordinated (even absolute ways/url are normally forbidden), the copy of the sent data is saved at the customer for possible trials. V> it to you good luck, such did not happen for a long time to me. And, well so it is room conditions, seriously. Any attempt to implement a pain-less difficult system at the new client very often leads to detection of any jambs. Optionally it is errors in the code (them just catch quickly). More often this combination of incorrect adjustment and special cases of several business rules which are separately formally true, but together lead to unobvious results. And it is good if it is noticeable things of type of the annual award in the tenfold size (, implementers on  changed 10 % on 10x) which are easily played back and diagnosed. Worse when similar small errors it is necessary to correct a post factum. Here then it is valid . V> If the jamb becomes a typical situation - it is necessary to change something in conservatory. The Brut-swagger does not help. In any large system always is what to repair/correct, it  as updates in win. To change in conservatory it is necessary, if the routine turns to a feat. The same "half-day on to correct" as a rule occupies hour four till the moment of delivery of a fix to the client. Well or, all same 4 hours on diagnostics "correction nontrivial, here to you a crutch, normally we repair with planned mailing of updates". V>>> we Return to a method from an example. V> my code - an example of my approach (without events). With events there are no special problems - there is remarkable library Rx which helps to cope with redirection of events on logs. Even easier to have the separate listener on each class of components. All is remarkable, only it does not concern in any way the delivered question: how to be with the real code which in 99 % of cases on  the model lays down ? Especially with knee-bends in the form of Rx which demands thorough knowledge  correctly to control subscription lifetime.

43

Re: Context transmission through set of abstraction layers of application

Hello, Sinix, you wrote: S> Hello, Vladek, you wrote: V>> User data will be in log - record of its actions. And further it is already possible to analyze locally that happens to the program after input of this data. If there there is a DB which is necessary for problem playback it is possible to be connected to it in a read mode or to use a copy. S> as they in log will be, if you only for debug builds write the information? It depends on a program configuration. In a simple case all is written to a file. S> bases do not give to you to 90 % of cases under no circumstances. - separate requests allow to span a maximum to the system administrator (only select, certainly), it checks up them, fulfills and spans reversely result (thus still, happens, is admitted to check only presence of records/values in fields but not to pull out the data). Contents of dens are in the same way coordinated (even absolute ways/url are normally forbidden), the copy of the sent data is saved at the customer for possible trials. It is solved, is normal also a DB is not necessary (a problem is shown at record of the new information) if all the same it is necessary - it . V>> It to you good luck, such did not happen for a long time to me. S> and, well so it is room conditions, seriously. Any attempt to implement a pain-less difficult system at the new client very often leads to detection of any jambs. Optionally it is errors in the code (them just catch quickly). More often this combination of incorrect adjustment and special cases of several business rules which are separately formally true, but together lead to unobvious results. And it is good if it is noticeable things of type of the annual award in the tenfold size (, implementers on  changed 10 % on 10x) which are easily played back and diagnosed. Worse when similar small errors it is necessary to correct a post factum. Here then it is valid . V>> If the jamb becomes a typical situation - it is necessary to change something in conservatory. The Brut-swagger does not help. S> in any large system always is what to repair/correct, it  as updates in win. To change in conservatory it is necessary, if the routine turns to a feat. The same "half-day on to correct" as a rule occupies hour four till the moment of delivery of a fix to the client. Well or, all same 4 hours on diagnostics "correction nontrivial, here to you a crutch, normally we repair with planned mailing of updates". Yes. Feats should not be. V>>>> we Return to a method from an example. V>> my code - an example of my approach (without events). With events there are no special problems - there is remarkable library Rx which helps to cope with redirection of events on logs. Even easier to have the separate listener on each class of components. S> All is remarkable, only it does not concern in any way the delivered question: how to be with the real code which in 99 % of cases on  the model lays down ? How does not lay down? The author specified a dial-up of events which happen in the program and influence operation with log (authentification, the publication of commands, start of parallel operations). Only at it these events in the code have no accurate representation - here and it is necessary to issue them explicitly - in the form of normal  events or still as. S> Especially with knee-bends in the form of Rx which demands thorough knowledge  correctly to control subscription lifetime.  it is necessary to know anyway. Life of components too should be absolutely clear from the code: here the component is born, here we get rid of it. The component itself can inform on the fast death separate event and the log will delete the subscription.

44

Re: Context transmission through set of abstraction layers of application

At me a simple variant. * to give  names in style VasyanVasyanov.SESSION14.PC123.CMDID123.THREAD111. * all to write to one broad gull and  by name .

45

Re: Context transmission through set of abstraction layers of application

Hello, LWhisper, you wrote: LW> Thanks for attention. 1. Whether at you  a heap  in one process that? It is not correct. Or it not . 2. If it is necessary to write in some conditions to info broad gull about the user that piece of the code which should do it causes a method  Write. If such a place make  a method to your volume to a class which owns  about the user much. Also use it. 3. In Trace. Listeners the writer did not try to palm off? By the way, to write to one file of their different flows forbids nobody.

46

Re: Context transmission through set of abstraction layers of application

Hello, VladCore, you wrote: whether VC> At you  a heap  in one process that? It is not correct. Or it not . And how.NET' practice to create on  on a class? class Some {public Some () {_log = LogFactory. Get (GetType ().Name);}}

47

Re: Context transmission through set of abstraction layers of application

Hello, UberPsychoSvin, you wrote: UPS> Hello, VladCore, you wrote: whether VC>> At you  a heap  in one process that? It is not correct. Or it not . UPS> And how.NET' practice, to create on  on a class? UPS> UPS> class Some UPS> {UPS> public Some () UPS> {UPS> _log = LogFactory. Get (GetType ().Name); UPS>} UPS>} UPS> LW> we Take, for an example, . LW> application Here is started and quickly starts to write a broad gull. The broad gull name goes down in arguments a command of a line. LW> Okej, is difficult to refuse it (though and it is possible) but while it is tolerant. LW> there is an authentification of the user. Now the broad gull is written already to the directory of this hapless user. Who selected for those did not read a question. By the way, this vicious practice with function _log = function (type_name) {....} came from . Once was abruptly. It should not be used. The topic-starter question see.