Is it considered poor design to create "black box" User Controls that communicate directly with the service layer (to perform CRUD operations, validation, etc)?
By "black box", I mean that they retrieve/persist data independently of the page they are hosted on (using IoC injected services). Each UC can be dropped onto a page and it will just work. 开发者_开发百科Mind you, there is no business logic embedded in any of these UCs whatsoever (that's all in the Domain layer).
This approach was driven by two factors:
- Our application has many pages that are essentially variants on the same view (with slightly different layouts).
Furthermore, our UI designer is fond of allowing discrete parts of a page to be opened up for editing. Click here for a poor attempt at illustrating this concept.
Anyway, it felt like giving the UCs the ability/responsibility to render and persist themselves would do away with quite a bit of code duplication.
If this approach is indeed considered "icky", please feel free to suggest an alternate one that is more appealing (perhaps MVP?) I'm stuck with WebForms for the foreseeable future.
Thanks!
Assuming you correctly implement the MVP pattern for each control in this fashion this is perfectly acceptable IMO.
Personally the way I have solved issues like this is allowing my MVP pattern to have hybrid view presenters that can access many views (think IListView
, IEditView
) however this would be more problematic to do if they're truly user controls since they half exist outside of the page to start with. If they're user controls with their own tags you can either implement it the way you asked in your quesiton or you need to expose all the possible events to implement the code on your pages.
No, this is actually how one goes about doing good SOA, where you have "stacks" that are relatively tightly coupled horizontally, loosely coupled with other "stacks" of functionality. The stacks are tied from the UI down to the persistence layer. Think how Amazon and EBay have pages, each page is a composite UI, each piece of the UI is independent of the other pieces, but within each piece the layers are dependent upon one another.
精彩评论