Topic: Context transmission through set of abstraction layers of application
All greetings. Came to collect time stones - to make architecture of application presentable. Now it is described by a well-aimed phrase "there is no time to think, it is necessary to dig". It is shown in everything, since cyclical in assembly, thanking , and finishing Constructor Injection c 28 dependences. If for the first it is necessary to tear off simply hands, last - a consequence of unreasoned architecture. But it already is and there is a question - as though to contrive and, without rewriting ten megabytes of the code, to result an existing disgrace in more or less adequate type. In this connection a question - what to do? 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. Here both Id sessions, and Id the current task, and a user id, and and still what the hell, on the person awful, inside. 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. For given by that context the DB, thanks to that it only one access is carried out through (sometime it is mandatory shoots - _-) appears. And here for all remaining it misses, and these dependences per aspera ad astra are pulled. We take, for an example, . Here application is started and quickly starts to write a broad gull. The broad gull name goes down in arguments a command of a line. , it is difficult to refuse it (though and it is possible) but while it is tolerant. There is an authentification of the user. Now the broad gull is written already to the directory of this hapless user. 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. 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. 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. 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. Here approximately and chains of arguments in designers and methods which from the version to the version become more and more are born. Sometimes you see a similar disgrace, you will contract 10 arguments into a minicontext, you will change calls. Month-other the code lives, and then lo and behold - was added two more arguments, and in your context superfluous properties which are necessary in 4 of 7 methods, but , naturally, always were added. The code becomes even more, suffers , productivity, and simple components acquire the difficult logic necessary for initialization of one of components of lower layer which simply does not know - where to it to write a broad gull. 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. In general, I will be grateful to any and which prompt - how to be in a similar situation. It is desirable, with real examples, close to the described situation with . What to do, where to look, what to read, what to study? What patterns approach, and what do not need to be touched in no event. If DP, with links to books and articles on the correct development and a configuration of this miracle in realities.NET. Thanks for attention.