dotnet / aspnetcore

ASP.NET Core is a cross-platform .NET framework for building modern cloud-based web applications on Windows, Mac, or Linux.
https://asp.net
MIT License
35.37k stars 9.99k forks source link

How to use DI in ICompileModule #328

Closed wwwlicious closed 9 years ago

wwwlicious commented 9 years ago

Looking for guidance in using IServiceProvider within the context of an ICompileModule.

I am creating a new appbuilder, passing in the existing IServiceProvider passed from the host app but was wondering if this is considered improper use. Example code can be found at the links

https://github.com/wwwlicious/R4MVC/blob/master/src/R4Mvc/R4MVCCompilerModule.cs#L38 https://github.com/wwwlicious/R4MVC/blob/master/src/R4Mvc/Ioc/IocConfig.cs

davidfowl commented 9 years ago

Why are you trying to extend what seems like the application via an ICompileModule?

wwwlicious commented 9 years ago

It was a suggestion by yourself here to follow the pattern of razorprecompiler. I may have misunderstood..?

davidfowl commented 9 years ago

Ah is this the T4MVC replacement?

wwwlicious commented 9 years ago

yes, so was just looking at the razorprecompiler and it makes a bit more sense now I'm a bit more familiar with a few bits.

So should I be creating a service collection just for the compiler module to use, that seems to be what razorprecompiler is doing?

davidfowl commented 9 years ago

Yes but currently, things generated by ICompileModules don't show up for intellisense in visual studio or omnisharp right now.

wwwlicious commented 9 years ago

ok, I am writing the r4mvc gen'd file out to disk which avoids that issue as it gets picked up by the compiler second time around, again probably a horrible thing to do but I just don't know any better at the moment :)