Startup-Tasks in (Web-)Anwendung

by Oliver 27. October 2010 19:42

Soeben las ich einen sehr interessanten Blog-Post von Ayende Rahien, in dem er Pluggability mittels MEF erwähnt. Scott Hanselman schreibt über MEF: “MEF is effectively a Dating Service for Components.”, also für mich eine Art von Dependency Injection und wahrscheinlich noch viel mehr.

Spannend für mich im o.g. Post von Ayende war das Konzept eines StartupTasks, den er einfach durch Implementierung eines Interfaces, IStartupTask, definiert, und den dann MEF für ihn verwaltet.

Wir nutzen ja Autofac für den Dependency Injection-Teil und mir kam die Idee, das Gleiche mit Autofac umzusetzen:

   1: public class Global : HttpApplication, IContainerProviderAccessor
   2: {
   3:     protected void Application_Start(object sender, EventArgs e)
   4:     {
   5:         var container = ...
   6:  
   7:         container
   8:             .ResolveAllImplementationsOf<IStartupTask>() // fake name :-)
   9:             .Select(task => task.Execute(...));
  10:     }
  11: }

Zugegebenermaßen kenn ich die richtige Syntax jetzt gerade nicht, aber es geht mir eher um die Idee. Wahrscheinlich kann man mit Hilfe von Autofac den StartupTasks auch Parameter mitgeben, ohne sie an dieser Stelle explizit anzugeben…

 

Mir gefällt’s.

 

Happy Coding,

Oliver

enjoyed the post?

Tags:

Add comment

  Country flag

biuquote
  • Comment
  • Preview
Loading

About Oliver

shades-of-orange.com code blog logo I build web applications using ASP.NET and have a passion for javascript. Enjoy MVC 4 and Orchard CMS, and I do TDD whenever I can. I like clean code. Love to spend time with my wife and our children. My profile on Stack Exchange, a network of free, community-driven Q&A sites

About Anton

shades-of-orange.com code blog logo I'm a software developer at teamaton. I code in C# and work with MVC, Orchard, SpecFlow, Coypu and NHibernate. I enjoy beach volleyball, board games and Coke.