Skip to content

Commit

Permalink
Introduce Volo.Abp.Autofac.WebAssembly package, move ABP application …
Browse files Browse the repository at this point in the history
…creation code to the framework.
  • Loading branch information
hikalkan committed Sep 13, 2020
1 parent 7d1a705 commit b510e00
Show file tree
Hide file tree
Showing 13 changed files with 166 additions and 18 deletions.
7 changes: 7 additions & 0 deletions framework/Volo.Abp.sln
Original file line number Diff line number Diff line change
Expand Up @@ -343,6 +343,8 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Volo.Abp.AspNetCore.Compone
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Volo.Abp.AspNetCore.Components.WebAssembly.Theming", "src\Volo.Abp.AspNetCore.Components.WebAssembly.Theming\Volo.Abp.AspNetCore.Components.WebAssembly.Theming.csproj", "{29CA7471-4E3E-4E75-8B33-001DDF682F01}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Volo.Abp.Autofac.WebAssembly", "src\Volo.Abp.Autofac.WebAssembly\Volo.Abp.Autofac.WebAssembly.csproj", "{37F89B0B-1C6B-426F-A5EE-676D1956D9E9}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Expand Down Expand Up @@ -1021,6 +1023,10 @@ Global
{29CA7471-4E3E-4E75-8B33-001DDF682F01}.Debug|Any CPU.Build.0 = Debug|Any CPU
{29CA7471-4E3E-4E75-8B33-001DDF682F01}.Release|Any CPU.ActiveCfg = Release|Any CPU
{29CA7471-4E3E-4E75-8B33-001DDF682F01}.Release|Any CPU.Build.0 = Release|Any CPU
{37F89B0B-1C6B-426F-A5EE-676D1956D9E9}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{37F89B0B-1C6B-426F-A5EE-676D1956D9E9}.Debug|Any CPU.Build.0 = Debug|Any CPU
{37F89B0B-1C6B-426F-A5EE-676D1956D9E9}.Release|Any CPU.ActiveCfg = Release|Any CPU
{37F89B0B-1C6B-426F-A5EE-676D1956D9E9}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
Expand Down Expand Up @@ -1194,6 +1200,7 @@ Global
{4EBDDB1B-D6C5-4FAE-B5A7-2171B18CDFA5} = {5DF0E140-0513-4D0D-BE2E-3D4D85CD70E6}
{ABC27C10-C0FF-44CB-B4FF-A09C0B79F695} = {5DF0E140-0513-4D0D-BE2E-3D4D85CD70E6}
{29CA7471-4E3E-4E75-8B33-001DDF682F01} = {5DF0E140-0513-4D0D-BE2E-3D4D85CD70E6}
{37F89B0B-1C6B-426F-A5EE-676D1956D9E9} = {5DF0E140-0513-4D0D-BE2E-3D4D85CD70E6}
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {BB97ECF4-9A84-433F-A80B-2A3285BDD1D5}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
using System;
using JetBrains.Annotations;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
using Volo.Abp;
using Volo.Abp.AspNetCore.Components.WebAssembly;
using Volo.Abp.Modularity;

namespace Microsoft.AspNetCore.Components.WebAssembly.Hosting
{
public static class AbpWebAssemblyHostBuilderExtensions
{
public static IAbpApplicationWithExternalServiceProvider AddApplication<TStartupModule>(
[NotNull] this WebAssemblyHostBuilder builder,
Action<AbpWebAssemblyApplicationCreationOptions> options)
where TStartupModule : IAbpModule
{
Check.NotNull(builder, nameof(builder));

builder.Services.AddSingleton<IConfiguration>(builder.Configuration);
builder.Services.AddSingleton(builder);

var application = builder.Services.AddApplication<TStartupModule>(opts =>
{
options?.Invoke(new AbpWebAssemblyApplicationCreationOptions(builder, opts));
});

return application;
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
using Microsoft.AspNetCore.Components.WebAssembly.Hosting;

namespace Volo.Abp.AspNetCore.Components.WebAssembly
{
public class AbpWebAssemblyApplicationCreationOptions
{
public WebAssemblyHostBuilder HostBuilder { get; }

public AbpApplicationCreationOptions ApplicationCreationOptions { get; }

public AbpWebAssemblyApplicationCreationOptions(
WebAssemblyHostBuilder hostBuilder,
AbpApplicationCreationOptions applicationCreationOptions)
{
HostBuilder = hostBuilder;
ApplicationCreationOptions = applicationCreationOptions;
}
}
}
3 changes: 3 additions & 0 deletions framework/src/Volo.Abp.Autofac.WebAssembly/FodyWeavers.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
<Weavers xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="FodyWeavers.xsd">
<ConfigureAwait ContinueOnCapturedContext="false" />
</Weavers>
30 changes: 30 additions & 0 deletions framework/src/Volo.Abp.Autofac.WebAssembly/FodyWeavers.xsd
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
<?xml version="1.0" encoding="utf-8"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema">
<!-- This file was generated by Fody. Manual changes to this file will be lost when your project is rebuilt. -->
<xs:element name="Weavers">
<xs:complexType>
<xs:all>
<xs:element name="ConfigureAwait" minOccurs="0" maxOccurs="1">
<xs:complexType>
<xs:attribute name="ContinueOnCapturedContext" type="xs:boolean" />
</xs:complexType>
</xs:element>
</xs:all>
<xs:attribute name="VerifyAssembly" type="xs:boolean">
<xs:annotation>
<xs:documentation>'true' to run assembly verification (PEVerify) on the target assembly after all weavers have been executed.</xs:documentation>
</xs:annotation>
</xs:attribute>
<xs:attribute name="VerifyIgnoreCodes" type="xs:string">
<xs:annotation>
<xs:documentation>A comma-separated list of error codes that can be safely ignored in assembly verification.</xs:documentation>
</xs:annotation>
</xs:attribute>
<xs:attribute name="GenerateXsd" type="xs:boolean">
<xs:annotation>
<xs:documentation>'false' to turn off automatic generation of the XML Schema file.</xs:documentation>
</xs:annotation>
</xs:attribute>
</xs:complexType>
</xs:element>
</xs:schema>
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
using System;
using Autofac;
using JetBrains.Annotations;
using Microsoft.Extensions.DependencyInjection;
using Volo.Abp;
using Volo.Abp.AspNetCore.Components.WebAssembly;

namespace Microsoft.AspNetCore.Components.WebAssembly.Hosting
{
public static class AbpWebAssemblyApplicationCreationOptionsAutofacExtensions
{
public static void UseAutofac(
[NotNull] this AbpWebAssemblyApplicationCreationOptions options,
[CanBeNull] Action<ContainerBuilder> configure = null)
{
options.HostBuilder.Services.AddAutofacServiceProviderFactory();
options.HostBuilder.ConfigureContainer(
options.HostBuilder.Services.GetSingletonInstance<IServiceProviderFactory<ContainerBuilder>>(),
configure
);
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<Project Sdk="Microsoft.NET.Sdk">

<Import Project="..\..\..\configureawait.props" />
<Import Project="..\..\..\common.props" />

<PropertyGroup>
<TargetFramework>netstandard2.1</TargetFramework>
<RootNamespace />
</PropertyGroup>

<ItemGroup>
<ProjectReference Include="..\Volo.Abp.AspNetCore.Components.WebAssembly\Volo.Abp.AspNetCore.Components.WebAssembly.csproj" />
<ProjectReference Include="..\Volo.Abp.Autofac\Volo.Abp.Autofac.csproj" />
</ItemGroup>

</Project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
using Volo.Abp.AspNetCore.Components.WebAssembly;
using Volo.Abp.Modularity;

namespace Volo.Abp.Autofac.WebAssembly
{
[DependsOn(
typeof(AbpAutofacModule),
typeof(AbpAspNetCoreComponentsWebAssemblyModule)
)]
public class AbpAutofacWebAssemblyModule : AbpModule
{

}
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,22 @@ public static class AbpAutofacAbpApplicationCreationOptionsExtensions
{
public static void UseAutofac(this AbpApplicationCreationOptions options)
{
var builder = new ContainerBuilder();
options.Services.AddObjectAccessor(builder);
options.Services.AddSingleton((IServiceProviderFactory<ContainerBuilder>) new AbpAutofacServiceProviderFactory(builder));
options.Services.AddAutofacServiceProviderFactory();
}

public static AbpAutofacServiceProviderFactory AddAutofacServiceProviderFactory(this IServiceCollection services)
{
return services.AddAutofacServiceProviderFactory(new ContainerBuilder());
}

public static AbpAutofacServiceProviderFactory AddAutofacServiceProviderFactory(this IServiceCollection services, ContainerBuilder containerBuilder)
{
var factory = new AbpAutofacServiceProviderFactory(containerBuilder);

services.AddObjectAccessor(containerBuilder);
services.AddSingleton((IServiceProviderFactory<ContainerBuilder>) factory);

return factory;
}
}
}
1 change: 1 addition & 0 deletions nupkg/common.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ $projects = (
"framework/src/Volo.Abp.Auditing",
"framework/src/Volo.Abp.Authorization",
"framework/src/Volo.Abp.Autofac",
"framework/src/Volo.Abp.Autofac.WebAssembly",
"framework/src/Volo.Abp.AutoMapper",
"framework/src/Volo.Abp.BackgroundJobs.Abstractions",
"framework/src/Volo.Abp.BackgroundJobs",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
</ItemGroup>

<ItemGroup>
<ProjectReference Include="..\..\..\..\..\framework\src\Volo.Abp.Autofac\Volo.Abp.Autofac.csproj" />
<ProjectReference Include="..\..\..\..\..\framework\src\Volo.Abp.Autofac.WebAssembly\Volo.Abp.Autofac.WebAssembly.csproj" />
<ProjectReference Include="..\..\..\..\..\framework\src\Volo.Abp.AspNetCore.Components.WebAssembly.BasicTheme\Volo.Abp.AspNetCore.Components.WebAssembly.BasicTheme.csproj" />
</ItemGroup>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,18 +7,18 @@
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
using Volo.Abp;
using Volo.Abp.Autofac;
using Volo.Abp.AspNetCore.Components.WebAssembly.BasicTheme;
using Volo.Abp.AspNetCore.Components.WebAssembly.BasicTheme.Themes.Basic;
using Volo.Abp.AspNetCore.Components.WebAssembly.Theming.Routing;
using Volo.Abp.Autofac.WebAssembly;
using Volo.Abp.Modularity;
using Volo.Abp.UI.Navigation;
using Volo.Abp.Identity.Blazor;

namespace MyCompanyName.MyProjectName.Blazor
{
[DependsOn(
typeof(AbpAutofacModule),
typeof(AbpAutofacWebAssemblyModule),
typeof(MyProjectNameHttpApiClientModule),
typeof(AbpIdentityBlazorModule),
typeof(AbpAspNetCoreComponentsWebAssemblyBasicThemeModule)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
using System.Threading.Tasks;
using Autofac;
using Microsoft.AspNetCore.Components.WebAssembly.Hosting;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
using Volo.Abp;
using Volo.Abp.AspNetCore.Mvc.Client;

namespace MyCompanyName.MyProjectName.Blazor
Expand All @@ -14,16 +11,10 @@ public static async Task Main(string[] args)
{
var builder = WebAssemblyHostBuilder.CreateDefault(args);

//TODO: Should be done in the ABP framework!
builder.Services.AddSingleton<IConfiguration>(builder.Configuration);
builder.Services.AddSingleton(builder);

var application = builder.Services.AddApplication<MyProjectNameBlazorModule>(opts =>
var application = builder.AddApplication<MyProjectNameBlazorModule>(options =>
{
opts.UseAutofac();
options.UseAutofac();
});

builder.ConfigureContainer(builder.Services.GetSingletonInstance<IServiceProviderFactory<ContainerBuilder>>());

var host = builder.Build();

Expand All @@ -35,7 +26,7 @@ await scope.ServiceProvider
.GetRequiredService<ICachedApplicationConfigurationClient>()
.InitializeAsync();
}

await host.RunAsync();
}
}
Expand Down

0 comments on commit b510e00

Please sign in to comment.