1

I anticipate having various assemblies that each contain a static class, with a static property, that might need to be "set" the moment the assembly they are in is loaded. This other post has an example of a static class that could benefit from such a procedure, such as when integration or unit tests are applied.

I wonder if there is any IOC Container that can register assembly load events, and use reflection in those events to find specified static class/property pairs, and set them - shortly after the assembly has loaded. Yes? No?

Community
  • 1
  • 1
Brent Arias
  • 29,277
  • 40
  • 133
  • 234
  • 2
    This smacks of the Singleton Pattern, which IoC Container lifetime management can eliminate. Are you *sure* you need static classes/properties? – TrueWill Jul 21 '10 at 03:47
  • For common (aka "shared" or "reusable") code, the "need" is to not require a dependency on an IOC Container (so that any IOC container can be used, or none at all). If an IOC container could do what I've described, I'd have the best of all worlds. (Now off-topic...) Anyway, I don't think any IOC container (Unity, Autofac, etc) can truly replace the singleton pattern because they either don't permit lazy assembly-load and instantiation of the single instance, or they don't gaurantee/encapsulate "to program end" lifecycle of the object created. – Brent Arias Jul 21 '10 at 18:44
  • You can write DI-friendly code without a DI container: http://stackoverflow.com/questions/2045904/dependency-inject-di-friendly-library/2047657#2047657 No need for Singletons. – Mark Seemann Jul 22 '10 at 05:42

0 Answers0