Skip to content

Commit

Permalink
Dunno about Windsor
Browse files Browse the repository at this point in the history
  • Loading branch information
jbogard committed Nov 30, 2022
1 parent 5853e12 commit 831973d
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 31 deletions.
7 changes: 0 additions & 7 deletions MediatR.sln
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,6 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "MediatR.Examples.SimpleInje
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "MediatR.Examples.Stashbox", "samples\MediatR.Examples.Stashbox\MediatR.Examples.Stashbox.csproj", "{F9148E20-5856-484C-8410-B515C6C56214}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "MediatR.Examples.Windsor", "samples\MediatR.Examples.Windsor\MediatR.Examples.Windsor.csproj", "{02C4C347-CC19-4D60-800D-8B62DBD89210}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Expand Down Expand Up @@ -107,10 +105,6 @@ Global
{F9148E20-5856-484C-8410-B515C6C56214}.Debug|Any CPU.Build.0 = Debug|Any CPU
{F9148E20-5856-484C-8410-B515C6C56214}.Release|Any CPU.ActiveCfg = Release|Any CPU
{F9148E20-5856-484C-8410-B515C6C56214}.Release|Any CPU.Build.0 = Release|Any CPU
{02C4C347-CC19-4D60-800D-8B62DBD89210}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{02C4C347-CC19-4D60-800D-8B62DBD89210}.Debug|Any CPU.Build.0 = Debug|Any CPU
{02C4C347-CC19-4D60-800D-8B62DBD89210}.Release|Any CPU.ActiveCfg = Release|Any CPU
{02C4C347-CC19-4D60-800D-8B62DBD89210}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
Expand All @@ -129,7 +123,6 @@ Global
{004D029A-43E7-47B0-BA74-D0A9F7FC7713} = {E372BF0B-90E8-4DC1-A332-F023095A3C2A}
{7CEB57F2-B6DC-4A18-A040-D12555C3D32F} = {E372BF0B-90E8-4DC1-A332-F023095A3C2A}
{F9148E20-5856-484C-8410-B515C6C56214} = {E372BF0B-90E8-4DC1-A332-F023095A3C2A}
{02C4C347-CC19-4D60-800D-8B62DBD89210} = {E372BF0B-90E8-4DC1-A332-F023095A3C2A}
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {D58286E3-878B-4ACB-8E76-F61E708D4339}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@

<ItemGroup>
<PackageReference Include="Castle.Windsor" Version="5.1.2" />
<PackageReference Include="Castle.Windsor.Extensions.DependencyInjection" Version="5.1.2" />
</ItemGroup>

</Project>
48 changes: 24 additions & 24 deletions samples/MediatR.Examples.Windsor/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -45,31 +45,31 @@ private static IMediator BuildMediator(WrappingWriter writer)

container.Register(Component.For<IMediator>().ImplementedBy<Mediator>());
container.Register(Component.For<TextWriter>().Instance(writer));
container.Register(Component.For<ServiceFactory>().UsingFactoryMethod<ServiceFactory>(k => (type =>
{
var enumerableType = type
.GetInterfaces()
.Concat(new[] { type })
.FirstOrDefault(t => t.IsGenericType && t.GetGenericTypeDefinition() == typeof(IEnumerable<>));

var service = enumerableType?.GetGenericArguments()?[0];
var resolvedType = enumerableType != null ? k.ResolveAll(service) : k.Resolve(type);
var genericArguments = service?.GetGenericArguments();

// Handle exceptions even using the base request types for IRequestExceptionHandler<,,>
var isRequestExceptionHandler = service?.GetGenericTypeDefinition()
?.IsAssignableTo(typeof(IRequestExceptionHandler<,,>)) ?? false;
if (isRequestExceptionHandler)
return ResolveRequestExceptionHandler(k, type, service, resolvedType, genericArguments);

// Handle exceptions even using the base request types for IRequestExceptionAction<,>
var isRequestExceptionAction = service?.GetGenericTypeDefinition()
?.IsAssignableTo(typeof(IRequestExceptionAction<,>)) ?? false;
if (isRequestExceptionAction)
return ResolveRequestExceptionAction(k, type, service, resolvedType, genericArguments);
//container.Register(Component.For<ServiceFactory>().UsingFactoryMethod<ServiceFactory>(k => (type =>
//{
// var enumerableType = type
// .GetInterfaces()
// .Concat(new[] { type })
// .FirstOrDefault(t => t.IsGenericType && t.GetGenericTypeDefinition() == typeof(IEnumerable<>));

// var service = enumerableType?.GetGenericArguments()?[0];
// var resolvedType = enumerableType != null ? k.ResolveAll(service) : k.Resolve(type);
// var genericArguments = service?.GetGenericArguments();

// // Handle exceptions even using the base request types for IRequestExceptionHandler<,,>
// var isRequestExceptionHandler = service?.GetGenericTypeDefinition()
// ?.IsAssignableTo(typeof(IRequestExceptionHandler<,,>)) ?? false;
// if (isRequestExceptionHandler)
// return ResolveRequestExceptionHandler(k, type, service, resolvedType, genericArguments);

// // Handle exceptions even using the base request types for IRequestExceptionAction<,>
// var isRequestExceptionAction = service?.GetGenericTypeDefinition()
// ?.IsAssignableTo(typeof(IRequestExceptionAction<,>)) ?? false;
// if (isRequestExceptionAction)
// return ResolveRequestExceptionAction(k, type, service, resolvedType, genericArguments);

return resolvedType;
})));
// return resolvedType;
//})));

//Pipeline
container.Register(Component.For(typeof(IStreamPipelineBehavior<,>)).ImplementedBy(typeof(GenericStreamPipelineBehavior<,>)));
Expand Down

0 comments on commit 831973d

Please sign in to comment.