Problema con la arquitectura de una aplicacion (referencias ciclicas)
Hola, tengo un problema con la arquitectura de capas. Necesito que dos capas se comuniquen de forma reciproca la una con la otra y no se como hacerlo para no hacer referencias ciclicas. Espero que me podais ayudar, gracias.
Una manera de aproximar este problema, si no puede ser evitado, es definir un conjunto externo de interfaces que definan las responsabilidades y funciones de cada capa en forma externa a la misma (normalmente en un assembly independiente), de forma tal que introducirlas como un tercer elemento rompan la referencia ciclica.
De esta forma, cada una de las dos capas implementara las interfaces que le corresponden, a la vez que usara las interfaces opuestas para interactuar con la otra capa. Para terminar de romper la dependencia ciclica, tienes que introducir un mecanismo que le permita obtener a cada capa una referencia a la implementacion de las interfaces comunes en la capa opuesta de forma completamente independiente. Una excelente manera de hacerlo es introduciendo un patron de "inyeccion de dependencias" o "inversion de control" que haga uso de factorias para hacer esta operacion. Martin Fowler tiene buena informacion en su sitio acerca de estos patrones (desafortunadamente no hay traduccion al espanol actualmente).
Afortunadamente hay varias librerias que ayudan a implementarlos, incluyendo spring.net, structuremap y otros. Personalmente, me gusta el contenedor Windsor.
One way of approaching this problem, if it cannot be avoided, is to define an external set of interfaces that define the responsabilities of each layer (usually in an independent assembly), in such a way that they can be introduced as a third element and break the cyclic reference.
In this way, each of the two layers will implement the corresponding interfaces, while at the same time using the opposing interfaces to interact with the other layer. To reall break up the cyclic dependency, you need to introduce a mechanism that allows each layer to get a reference to the other layer's implementation of the common interfaces without directly instantiating the implementation classes. An excellent way of accomplishing this is through the use of Dependency Injection or Inversion of Control patterns that make use of factories to do this. Martin Fowler has good information on his site about this patterns.
Fortunately, there are several libraries available that help implementing them, like spring.net, structuremap and others. Personally, I like using the Windsor container in the Castle Project.
Hello, I have a problem with the architecture of layers. I need that two layers communicate of reciprocal form the one with the other and I do not know how to make it not to make referencias cyclical. I hope that podais to help me, thanks.
Problema con la arquitectura de una aplicacion (referencias ciclicas)
Professor Frink
Una manera de aproximar este problema, si no puede ser evitado, es definir un conjunto externo de interfaces que definan las responsabilidades y funciones de cada capa en forma externa a la misma (normalmente en un assembly independiente), de forma tal que introducirlas como un tercer elemento rompan la referencia ciclica.
De esta forma, cada una de las dos capas implementara las interfaces que le corresponden, a la vez que usara las interfaces opuestas para interactuar con la otra capa. Para terminar de romper la dependencia ciclica, tienes que introducir un mecanismo que le permita obtener a cada capa una referencia a la implementacion de las interfaces comunes en la capa opuesta de forma completamente independiente. Una excelente manera de hacerlo es introduciendo un patron de "inyeccion de dependencias" o "inversion de control" que haga uso de factorias para hacer esta operacion. Martin Fowler tiene buena informacion en su sitio acerca de estos patrones (desafortunadamente no hay traduccion al espanol actualmente).
Afortunadamente hay varias librerias que ayudan a implementarlos, incluyendo spring.net, structuremap y otros. Personalmente, me gusta el contenedor Windsor.
--------------------------------------------------------------------------------------------------
One way of approaching this problem, if it cannot be avoided, is to define an external set of interfaces that define the responsabilities of each layer (usually in an independent assembly), in such a way that they can be introduced as a third element and break the cyclic reference.
In this way, each of the two layers will implement the corresponding interfaces, while at the same time using the opposing interfaces to interact with the other layer. To reall break up the cyclic dependency, you need to introduce a mechanism that allows each layer to get a reference to the other layer's implementation of the common interfaces without directly instantiating the implementation classes. An excellent way of accomplishing this is through the use of Dependency Injection or Inversion of Control patterns that make use of factories to do this. Martin Fowler has good information on his site about this patterns.
Fortunately, there are several libraries available that help implementing them, like spring.net, structuremap and others. Personally, I like using the Windsor container in the Castle Project.
Inferno986
RajDas