Take the 2-minute tour ×
Programmers Stack Exchange is a question and answer site for professional programmers interested in conceptual questions about software development. It's 100% free, no registration required.

I'm building a component that manages available resources (JavaScript and CSS files) for a web page.

As controls are added to the page, they register and un-register their requirements with this manager. Then at render time the manager only renders <script> and <link> tags for the required resources.

A basic implementation would be to have a dictionary with the resource URL as the key and a list of dependent controls as the value. Then at render time, if the list is empty, don't render the resource.

I'm wondering if there is an established pattern for this?

I'm using ASP.NET and C# if that bares any significance.

UPDATE

I was thinking about it and while the manager is controlling the dependencies of the controls of the page, the fact that they are dependencies is almost superfluous to my question.

I think what I'm looking for is something like the Observer Pattern but the observers don't require being notified, the manager simply needs to maintain a list of subscribers.

share|improve this question
add comment

1 Answer 1

There's a pattern that solves something like that called Dependency Injection. There are containers (kind of specialized dictionaries) that contain resources. Although that pattern is specific for object instantiation I don't see why not extend it to your needs.

share|improve this answer
2  
Useful article on dependency injection - martinfowler.com/articles/injection.html –  Steve314 Aug 6 '11 at 18:26
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.