Skip to content

Commit

Permalink
ASP.NET Core facility using Cross Wiring
Browse files Browse the repository at this point in the history
Provides integration with ASP.NET Core with first class support for Controllers, TagHelpers, ViewComponents and Middleware(needing Windsor).

You can expose your Windsor registrations to third party libraries that use IServiceCollection by registering them with the `CrossWired`
component registration extension. This will for example make things like @Inject work.

Docs:
 - https://github.com/castleproject/Windsor/blob/master/docs/aspnetcore-facility.md

Thanks to:
 - @dotnetjunkie
 - @generik0
 - @hikalkan
 - @ploeh
  • Loading branch information
Gavin van der Merwe committed Jul 1, 2018
1 parent 9b4d1fb commit 322a39c
Show file tree
Hide file tree
Showing 33 changed files with 2,844 additions and 476 deletions.
207 changes: 150 additions & 57 deletions docs/aspnetcore-facility.md

Large diffs are not rendered by default.

192 changes: 0 additions & 192 deletions src/Castle.Facilities.AspNetCore.Tests/AspNetCoreFacilityTestCase.cs

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -20,4 +20,23 @@
<ProjectReference Include="..\Castle.Facilities.AspNetCore\Castle.Facilities.AspNetCore.csproj" />
</ItemGroup>

<ItemGroup>
<None Update="Fakes\ModelFakes.tt">
<Generator>TextTemplatingFileGenerator</Generator>
<LastGenOutput>ModelFakes.cs</LastGenOutput>
</None>
</ItemGroup>

<ItemGroup>
<Service Include="{508349b6-6b84-4df5-91f0-309beebad82d}" />
</ItemGroup>

<ItemGroup>
<Compile Update="Fakes\ModelFakes.cs">
<DesignTime>True</DesignTime>
<AutoGen>True</AutoGen>
<DependentUpon>ModelFakes.tt</DependentUpon>
</Compile>
</ItemGroup>

</Project>
64 changes: 64 additions & 0 deletions src/Castle.Facilities.AspNetCore.Tests/Fakes/AnyFakes.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
// Copyright 2004-2018 Castle Project - http://www.castleproject.org/
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.


namespace Castle.Facilities.AspNetCore.Tests.Fakes
{
using System;
using System.Threading.Tasks;

using Microsoft.AspNetCore.Http;

using Castle.MicroKernel.Lifestyle;

public class AnyComponent { }
public class AnyComponentWithLifestyleManager : AbstractLifestyleManager
{
public override void Dispose()
{
}
}

public sealed class AnyMiddleware : IMiddleware
{
private readonly AnyComponent anyComponent;
private readonly ServiceProviderOnlyScopedDisposable serviceProviderOnlyScopedDisposable;
private readonly WindsorOnlyScopedDisposable windsorOnlyScopedDisposable;
private readonly CrossWiredScopedDisposable crossWiredScopedDisposable;

public AnyMiddleware(
ServiceProviderOnlyScopedDisposable serviceProviderOnlyScopedDisposable,
WindsorOnlyScopedDisposable windsorOnlyScopedDisposable,
CrossWiredScopedDisposable crossWiredScopedDisposable)
{
this.serviceProviderOnlyScopedDisposable = serviceProviderOnlyScopedDisposable ?? throw new ArgumentNullException(nameof(serviceProviderOnlyScopedDisposable));
this.windsorOnlyScopedDisposable = windsorOnlyScopedDisposable ?? throw new ArgumentNullException(nameof(windsorOnlyScopedDisposable));
this.crossWiredScopedDisposable = crossWiredScopedDisposable ?? throw new ArgumentNullException(nameof(crossWiredScopedDisposable));
}

public AnyMiddleware(AnyComponent anyComponent)
{
// This will never get called because Windsor picks the most greedy constructor
this.anyComponent = anyComponent ?? throw new ArgumentNullException(nameof(anyComponent));
}

public async Task InvokeAsync(HttpContext context, RequestDelegate next)
{
// Do something before
await next(context);
// Do something after
}
}

}
57 changes: 57 additions & 0 deletions src/Castle.Facilities.AspNetCore.Tests/Fakes/CompositeFakes.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
// Copyright 2004-2018 Castle Project - http://www.castleproject.org/
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

namespace Castle.Facilities.AspNetCore.Tests.Fakes
{
using System;

public class CompositeController
{
public CompositeController(
ControllerCrossWired crossWiredController,
ControllerServiceProviderOnly serviceProviderOnlyController,
ControllerWindsorOnly windsorOnlyController)
{
if (crossWiredController == null) throw new ArgumentNullException(nameof(crossWiredController));
if (serviceProviderOnlyController == null) throw new ArgumentNullException(nameof(serviceProviderOnlyController));
if (windsorOnlyController == null) throw new ArgumentNullException(nameof(windsorOnlyController));
}
}

public class CompositeTagHelper
{
public CompositeTagHelper(
TagHelperCrossWired crossWiredTagHelper,
TagHelperServiceProviderOnly serviceProviderOnlyTagHelper,
TagHelperWindsorOnly windsorOnlyTagHelper)
{
if (crossWiredTagHelper == null) throw new ArgumentNullException(nameof(crossWiredTagHelper));
if (serviceProviderOnlyTagHelper == null) throw new ArgumentNullException(nameof(serviceProviderOnlyTagHelper));
if (windsorOnlyTagHelper == null) throw new ArgumentNullException(nameof(windsorOnlyTagHelper));
}
}

public class CompositeViewComponent
{
public CompositeViewComponent(
ViewComponentCrossWired crossWiredViewComponent,
ViewComponentServiceProviderOnly serviceProviderOnlyViewComponent,
ViewComponentWindsorOnly windsorOnlyViewComponent)
{
if (crossWiredViewComponent == null) throw new ArgumentNullException(nameof(crossWiredViewComponent));
if (serviceProviderOnlyViewComponent == null) throw new ArgumentNullException(nameof(serviceProviderOnlyViewComponent));
if (windsorOnlyViewComponent == null) throw new ArgumentNullException(nameof(windsorOnlyViewComponent));
}
}
}
Loading

0 comments on commit 322a39c

Please sign in to comment.