Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

T4MVC Use Extension methods in Control Library

I have written a few razor helpers and these helpers use functions that include the extension methods generated by T4MVC. I now want to move these to a control library so that they can be used across multiple mvc applications. The initial idea that I have used is that I can put a copy of the template into the control library, and this works, the downside is that the template used in the application then regenerates the same extension methods in the same namespace. Because I am using some of the extension that require the interface for the ActionResult I do need that the namespace remains the same.

What I am wondering is, is there a known way to use the extensions in a control library as well as an application that references the library, or is a change to the template required such that the static extension methods can be either generated or not via a flag in the settings file? I am also wondering if the static extensions could be included in a separate cs file that lives along side the template. So that we have 2 classes T4Extensions and DynamicT4Extensions?

This might force the use of the interface IT4MVCActionResult though,

like image 262
Dewy Avatar asked Nov 06 '22 00:11

Dewy


1 Answers

This is similar but not quite the same as http://forums.asp.net/p/1510753/3603100.aspx.

I wonder if the solution might be to add a new switch in the settings file that would turn off the generation of those static methods. So if you know you're already getting them from some referenced assembly, you'd turn them off in the app.

Though that might still blow up if you have multiple unrelated libraries that each need to use the methods, as the app would then get an ambiguous reference.

Note that we can't make the methods internal, since some of them need to be called from views, which live in different assemblies.

And ideally, I'd prefer to avoid having those in yet a separate file, as some users may start complaining that T4MVC brings in too many files.

Sorry, not really a clear answer, but more thinking through possibilities. :)

like image 55
David Ebbo Avatar answered Nov 09 '22 17:11

David Ebbo