Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Microsoft di and roslyn compiler #77

Merged
merged 14 commits into from
Apr 24, 2024

Conversation

bounav
Copy link
Collaborator

@bounav bounav commented Jan 24, 2024

Using the Microsoft.Extensions.DependencyInjection apis to resolve dependencies

  • Removed ISparkServiceInitialize and ISparkServiceContainer (and it's implementation)
  • Constructor injection is used instead of auto-initializing properties
  • New IBatchCompiler interface so that we can use different compilers
    • ~2x performance improvement when compiling views with Roslyn
    • CodeDom compilation can still be used at the moment (class marked as obsolete)
    • CodeDom marked as obsolete (as it will not generating code for .net core) and wrapped into #if NETFRAMEWORK block
  • Fixed a bug preventing the pre-compilation of templates for a generic controller
  • New implementation of ICacheService that is works on .net standard (InMemoryCache)

bounav and others added 7 commits January 24, 2024 09:20
…ependencies

- Now using constructor injection instead of auto-initializing properties
- Removed ISparkServiceInitialize and ISparkServiceContainer (and it's implementation)
- New IBatchCompiler interface so that we can use different compilers
- ~2x performance improvement when compiling views with Roslyn
- CodeDom compilation can still be used at the moment (class marked as obsolete)
- CastleMonoRail still using codedom (rosylin doesn't like the assembly name when compiling in that project)
…ewEngine/spark into microsoft-di-and-roslyn-compiler
- CodeDom complilation cannot target .net core
- BatchCompiler.cs contains the code to complile with codedom and/or roslyn
@bounav bounav marked this pull request as draft February 13, 2024 10:58
@bounav
Copy link
Collaborator Author

bounav commented Feb 13, 2024

I found a problem when using roslyn to compile the views: each time a view is compiled, an assembly is loaded into memory and never released. This means spark eats up all the memory available and eventually OutOfMemoryException are thrown.

@RobertTheGrey
Copy link
Member

RobertTheGrey commented Feb 13, 2024 via email

- Improved readability of RemoveSuffix method
- Renamed ISparkSettings.PageBaseType to BaseClassTypeName
- An instance of ISparkSettings is used instead of duplicated properties on the ViewCompiler base class
- New ISparkSettings.ExcludeAssemblies property that can be used to the prevent the view compiler from loading .DLLs that would containt precompile views (and would might already be loaded)
- Replaced by a callback in the IoC configuration
- See ServiceCollectionExtensions.cs
- InMemoryCacheService cache can be used in any .net standard project
- CacheExpires class not longer has depenency on System.Web.Caching.Cache
- Renamed DefaultCacheService to WebCacheService
- Moved NullCacheService to Castle.MonoRail.Views project (it's the only place using it)
- Moved some classes back to Spark project when possible
- Moved markdown dependency back to spark
- Use of a new SparkRouteData class
- Avoids having a dependency on Microsoft.AspNet.Mvc
@bounav
Copy link
Collaborator Author

bounav commented Apr 19, 2024

I can't think of a fix for .net framework. I think the best it to carry on using the non roslyn compiler.
I have been using the roslyn compiler to precompile the views (much faster) at build time that said (memory usage is not really a concern then.

For .net core, loading the assemblies into a MetadataLoadContext might be an avenue to explore?

@RobertTheGrey
Copy link
Member

Is it worth going down the Source Generation route during compile time maybe?

@bounav
Copy link
Collaborator Author

bounav commented Apr 24, 2024

Is it worth going down the Source Generation route during compile time maybe?

Definitely something worth exploring. It would be ideal to have the same options/behaviour as with MVC Razor (e.g. the choice to compile the views are build time (default) or to leave it for later at runtime).

I couldn't find any docs explaining how Microsoft does compile their razor views at build time...

@RobertTheGrey RobertTheGrey merged commit 544fcb7 into master Apr 24, 2024
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants