-
Notifications
You must be signed in to change notification settings - Fork 221
Aspirify local dev #1365
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
Open
Meir017
wants to merge
2
commits into
ashmind:main
Choose a base branch
from
Meir017:feature/aspire
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Aspirify local dev #1365
Changes from 1 commit
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,30 @@ | ||
| using System.Numerics; | ||
|
|
||
| var builder = DistributedApplication.CreateBuilder(args); | ||
|
|
||
| var webappPort = builder.AddParameter("webapp-port", "44200"); | ||
|
|
||
| var storage = builder.AddAzureStorage("storage") | ||
| .RunAsEmulator(options => options.WithLifetime(ContainerLifetime.Persistent).WithBlobPort(10000)); | ||
| var storageBlob = storage.AddBlobs("cache"); | ||
| var blobContainer = storageBlob.AddBlobContainer("edge"); | ||
|
|
||
| var containerManager = builder.AddProject<Projects.Container_Manager>("container-manager"); | ||
|
|
||
| var installWebApp = builder.AddExecutable("install-webapp", "npm", "../WebApp", "install"); | ||
| var buildWebApp = builder.AddExecutable("build-webapp", "npm", "../WebApp", "run", "build") | ||
| .WithParentRelationship(installWebApp) | ||
| .WaitForCompletion(installWebApp); | ||
| var webapp = builder.AddNpmApp("webapp", "../WebApp", scriptName: "start:fast") | ||
| .WaitForCompletion(buildWebApp) | ||
| .WithHttpEndpoint(env: "PORT") | ||
| .WithEnvironment("PORT", webappPort) | ||
| .WithEnvironment("test", blobContainer).WaitFor(blobContainer); | ||
| installWebApp.WithParentRelationship(webapp); | ||
|
|
||
| var webappServer = builder.AddProject<Projects.WebApp_Server>("webapp-server") | ||
| .WaitFor(webapp) | ||
| .WaitFor(containerManager) | ||
| .WithEnvironment("SHARPLAB_LOCAL_SECRETS_PublicStorageConnectionString", storageBlob).WaitFor(storageBlob); | ||
|
|
||
| builder.Build().Run(); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,24 @@ | ||
| <Project Sdk="Microsoft.NET.Sdk"> | ||
|
|
||
| <Sdk Name="Aspire.AppHost.Sdk" Version="9.3.0" /> | ||
|
|
||
| <PropertyGroup> | ||
| <OutputType>Exe</OutputType> | ||
| <TargetFramework>net9.0</TargetFramework> | ||
| <ImplicitUsings>enable</ImplicitUsings> | ||
| <Nullable>enable</Nullable> | ||
| <UserSecretsId>9cc6fba6-3727-4501-b54b-d61cf8eae623</UserSecretsId> | ||
| </PropertyGroup> | ||
|
|
||
| <ItemGroup> | ||
| <PackageReference Include="Aspire.Hosting.AppHost" Version="9.3.0" /> | ||
| <PackageReference Include="Aspire.Hosting.Azure.Storage" Version="9.3.0" /> | ||
| <PackageReference Include="Aspire.Hosting.NodeJs" Version="9.3.0" /> | ||
| </ItemGroup> | ||
|
|
||
| <ItemGroup> | ||
| <ProjectReference Include="..\WebApp.Server\WebApp.Server.csproj" /> | ||
| <ProjectReference Include="..\Container.Manager\Container.Manager.csproj" /> | ||
| </ItemGroup> | ||
|
|
||
| </Project> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,13 @@ | ||
| # Aspire Setup | ||
|
|
||
| run: | ||
|
|
||
| ```bash | ||
| git submodule update --init --recursive | ||
| ``` | ||
|
|
||
| # Aspire AppHost | ||
|
|
||
| ```bash | ||
| dotnet run --project source/AppHost | ||
| ``` |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,8 @@ | ||
| { | ||
| "Logging": { | ||
| "LogLevel": { | ||
| "Default": "Information", | ||
| "Microsoft.AspNetCore": "Warning" | ||
| } | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,9 @@ | ||
| { | ||
| "Logging": { | ||
| "LogLevel": { | ||
| "Default": "Information", | ||
| "Microsoft.AspNetCore": "Warning", | ||
| "Aspire.Hosting.Dcp": "Warning" | ||
| } | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
85 changes: 85 additions & 0 deletions
85
source/Server/Autofac.Extras.FileSystemRegistration/DirectoryModuleRegistrar.cs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,85 @@ | ||
| using System; | ||
| using System.IO; | ||
| using System.Linq; | ||
| using System.Reflection; | ||
| using Autofac.Core; | ||
| using Autofac.Core.Registration; | ||
| using JetBrains.Annotations; | ||
|
|
||
| namespace Autofac.Extras.FileSystemRegistration.Internal { | ||
| public class DirectoryModuleRegistrar : IDirectoryModuleRegistrar { | ||
| private readonly ContainerBuilder _builder; | ||
| private readonly string[] _directoryPaths; | ||
|
|
||
| private string _filePattern = "*.*"; | ||
| private Func<FileInfo, bool> _fileFilter = f => f.Extension.Equals(".dll", StringComparison.InvariantCultureIgnoreCase) | ||
| || f.Extension.Equals(".exe", StringComparison.InvariantCultureIgnoreCase); | ||
| private Func<Assembly, bool> _assemblyFilter = a => true; | ||
|
|
||
| public DirectoryModuleRegistrar([NotNull] ContainerBuilder builder, params string[] directoryPaths) | ||
| { | ||
| ArgumentNullException.ThrowIfNull(builder); | ||
| _builder = builder; | ||
| _directoryPaths = directoryPaths; | ||
|
|
||
| var callback = _builder.RegisterCallback(DiscoverModules); | ||
| RegistrarData = new ModuleRegistrarData(callback); | ||
| } | ||
|
|
||
| public ModuleRegistrarData RegistrarData { get; } | ||
|
|
||
| public IDirectoryModuleRegistrar WhereFileMatches(string filePattern) | ||
| { | ||
| ArgumentNullException.ThrowIfNull(filePattern); | ||
|
|
||
| _filePattern = filePattern; | ||
| return this; | ||
| } | ||
|
|
||
| public IDirectoryModuleRegistrar WhereFile(Func<FileInfo, bool> filter) { | ||
| ArgumentNullException.ThrowIfNull(filter); | ||
|
|
||
| _fileFilter = filter; | ||
| return this; | ||
| } | ||
|
|
||
| public IDirectoryModuleRegistrar WhereAssembly(Func<Assembly, bool> filter) { | ||
| ArgumentNullException.ThrowIfNull(filter); | ||
|
|
||
| _assemblyFilter = filter; | ||
| return this; | ||
| } | ||
|
|
||
| private void DiscoverModules(IComponentRegistryBuilder registry) { | ||
| var files = _directoryPaths.Select(p => new DirectoryInfo(p)) | ||
| .SelectMany(d => d.GetFiles(_filePattern)) | ||
| .Where(_fileFilter); | ||
|
|
||
| var registrar = new ImmediateModuleRegistrar(registry, this.RegistrarData); | ||
| foreach (var file in files) { | ||
| var assembly = LoadAssemblySafe(file); | ||
| if (assembly == null || !_assemblyFilter(assembly)) | ||
| continue; | ||
|
|
||
| registrar.RegisterAssemblyModules(assembly); | ||
| } | ||
| } | ||
|
|
||
| [CanBeNull] | ||
| private static Assembly? LoadAssemblySafe(FileInfo file) { | ||
| try { | ||
| return Assembly.LoadFrom(file.FullName); | ||
| } | ||
| catch (BadImageFormatException) { | ||
| return null; | ||
| } | ||
| } | ||
|
|
||
| [NotNull] | ||
| public IModuleRegistrar RegisterModule([NotNull] IModule module) { | ||
| ArgumentNullException.ThrowIfNull(module); | ||
| _builder.RegisterCallback(module.Configure); | ||
| return this; | ||
| } | ||
| } | ||
| } |
13 changes: 13 additions & 0 deletions
13
source/Server/Autofac.Extras.FileSystemRegistration/IDirectoryModuleRegistrar.cs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,13 @@ | ||
| using System; | ||
| using System.IO; | ||
| using System.Reflection; | ||
| using Autofac.Core.Registration; | ||
| using JetBrains.Annotations; | ||
|
|
||
| namespace Autofac.Extras.FileSystemRegistration.Internal { | ||
| public interface IDirectoryModuleRegistrar : IModuleRegistrar { | ||
| [NotNull] IDirectoryModuleRegistrar WhereFileMatches([NotNull] string filePattern); | ||
| [NotNull] IDirectoryModuleRegistrar WhereFile([NotNull] Func<FileInfo, bool> filter); | ||
| [NotNull] IDirectoryModuleRegistrar WhereAssembly([NotNull] Func<Assembly, bool> filter); | ||
| } | ||
| } |
29 changes: 29 additions & 0 deletions
29
source/Server/Autofac.Extras.FileSystemRegistration/ImmediateModuleRegistrar.cs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,29 @@ | ||
| using System; | ||
| using Autofac.Core; | ||
| using Autofac.Core.Registration; | ||
| using JetBrains.Annotations; | ||
|
|
||
| namespace Autofac.Extras.FileSystemRegistration.Internal | ||
| { | ||
| public class ImmediateModuleRegistrar : IModuleRegistrar | ||
| { | ||
| private readonly IComponentRegistryBuilder _registry; | ||
|
|
||
| public ImmediateModuleRegistrar([NotNull] IComponentRegistryBuilder registry, ModuleRegistrarData registrarData) | ||
| { | ||
| ArgumentNullException.ThrowIfNull(registry); | ||
| ArgumentNullException.ThrowIfNull(registrarData); | ||
|
|
||
| _registry = registry; | ||
| RegistrarData = registrarData; | ||
| } | ||
|
|
||
| public ModuleRegistrarData RegistrarData { get; } | ||
|
|
||
| public IModuleRegistrar RegisterModule(IModule module) | ||
| { | ||
| module.Configure(_registry); | ||
| return this; | ||
| } | ||
| } | ||
| } |
22 changes: 22 additions & 0 deletions
22
source/Server/Autofac.Extras.FileSystemRegistration/RegistrationExtensions.cs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,22 @@ | ||
| using System; | ||
| using System.IO; | ||
| using System.Reflection; | ||
| using Autofac.Extras.FileSystemRegistration.Internal; | ||
| using JetBrains.Annotations; | ||
|
|
||
| namespace Autofac.Extras.FileSystemRegistration { | ||
| [PublicAPI] | ||
| public static class RegistrationExtensions { | ||
| [PublicAPI, NotNull] | ||
| public static IDirectoryModuleRegistrar RegisterAssemblyModulesInDirectories([NotNull] this ContainerBuilder builder, params string[] directoryPaths) { | ||
| return new DirectoryModuleRegistrar(builder, directoryPaths); | ||
| } | ||
|
|
||
| [PublicAPI, NotNull] | ||
| public static IDirectoryModuleRegistrar RegisterAssemblyModulesInDirectoryOf([NotNull] this ContainerBuilder builder, Assembly assembly) { | ||
| if (assembly == null) throw new ArgumentNullException("assembly"); | ||
| var directoryPath = Path.GetDirectoryName(new Uri(assembly.Location).LocalPath); | ||
| return builder.RegisterAssemblyModulesInDirectories(directoryPath!); | ||
| } | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,18 +1,26 @@ | ||
| using Microsoft.AspNetCore.Hosting; | ||
| using Microsoft.Extensions.Hosting; | ||
| using Autofac.Extensions.DependencyInjection; | ||
| using SharpLab.Server.Common; | ||
| using Microsoft.AspNetCore.Builder; | ||
| using Autofac; | ||
|
|
||
| namespace SharpLab.Server { | ||
| public class Program { | ||
| public static void Main(string[] args) { | ||
| DotEnv.Load(); | ||
| CreateHostBuilder(args).Build().Run(); | ||
| } | ||
|
|
||
| public static IHostBuilder CreateHostBuilder(string[] args) => | ||
| Host.CreateDefaultBuilder(args) | ||
| .UseServiceProviderFactory(new AutofacServiceProviderFactory()) | ||
| .ConfigureWebHostDefaults(webBuilder => webBuilder.UseStartup<Startup>()); | ||
| var builder = WebApplication.CreateBuilder(args); | ||
| builder.AddServiceDefaults(); | ||
| builder.Host.UseServiceProviderFactory(new AutofacServiceProviderFactory()); | ||
|
|
||
| var startup = new Startup(); | ||
| startup.ConfigureServices(builder.Services); | ||
| builder.Host.ConfigureContainer<ContainerBuilder>(startup.ConfigureContainer); | ||
|
|
||
| var app = builder.Build(); | ||
| app.MapDefaultEndpoints(); | ||
| startup.Configure(app, app.Environment); | ||
| app.Run(); | ||
| } | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
the old version of Autofac togather with the new
AddServiceDefaultsfailed to start with the errorThere was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
updating Autofac to a recent version broke the dependency on
Autofac.Extras.FileSystemRegistrationSo I copied the source-files of that library into a folder in this component