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.


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.


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.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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