mirror of
https://github.com/Ombi-app/Ombi.git
synced 2025-08-14 02:26:55 -07:00
Plugged in MediatR
This commit is contained in:
parent
d4074fc0f3
commit
7a6ee7e98d
7 changed files with 151 additions and 21 deletions
|
@ -15,6 +15,14 @@
|
|||
<assemblyIdentity name="Microsoft.Owin" publicKeyToken="31bf3856ad364e35" culture="neutral" />
|
||||
<bindingRedirect oldVersion="0.0.0.0-3.0.1.0" newVersion="3.0.1.0" />
|
||||
</dependentAssembly>
|
||||
<dependentAssembly>
|
||||
<assemblyIdentity name="Ninject" publicKeyToken="c7192dc5380945e7" culture="neutral" />
|
||||
<bindingRedirect oldVersion="0.0.0.0-3.2.0.0" newVersion="3.2.0.0" />
|
||||
</dependentAssembly>
|
||||
<dependentAssembly>
|
||||
<assemblyIdentity name="Ninject.Extensions.ChildKernel" publicKeyToken="c7192dc5380945e7" culture="neutral" />
|
||||
<bindingRedirect oldVersion="0.0.0.0-3.2.0.0" newVersion="3.2.0.0" />
|
||||
</dependentAssembly>
|
||||
</assemblyBinding>
|
||||
</runtime>
|
||||
<appSettings>
|
||||
|
|
65
PlexRequests.UI/Helpers/ContravariantBindingResolver.cs
Normal file
65
PlexRequests.UI/Helpers/ContravariantBindingResolver.cs
Normal file
|
@ -0,0 +1,65 @@
|
|||
#region Copyright
|
||||
// /************************************************************************
|
||||
// Copyright (c) 2016 Jamie Rees
|
||||
// File: ContravariantBindingResolver.cs
|
||||
// Created By: Jamie Rees
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person obtaining
|
||||
// a copy of this software and associated documentation files (the
|
||||
// "Software"), to deal in the Software without restriction, including
|
||||
// without limitation the rights to use, copy, modify, merge, publish,
|
||||
// distribute, sublicense, and/or sell copies of the Software, and to
|
||||
// permit persons to whom the Software is furnished to do so, subject to
|
||||
// the following conditions:
|
||||
//
|
||||
// The above copyright notice and this permission notice shall be
|
||||
// included in all copies or substantial portions of the Software.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
||||
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
||||
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
||||
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
||||
// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
||||
// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
||||
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
// ************************************************************************/
|
||||
#endregion
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Reflection;
|
||||
|
||||
using Ninject.Components;
|
||||
using Ninject.Infrastructure;
|
||||
using Ninject.Planning.Bindings;
|
||||
using Ninject.Planning.Bindings.Resolvers;
|
||||
|
||||
namespace PlexRequests.UI.Helpers
|
||||
{
|
||||
public class ContravariantBindingResolver : NinjectComponent, IBindingResolver
|
||||
{
|
||||
/// <summary>
|
||||
/// Returns any bindings from the specified collection that match the specified service.
|
||||
/// </summary>
|
||||
public IEnumerable<IBinding> Resolve(Multimap<Type, IBinding> bindings, Type service)
|
||||
{
|
||||
if (service.IsGenericType)
|
||||
{
|
||||
var genericType = service.GetGenericTypeDefinition();
|
||||
var genericArguments = genericType.GetGenericArguments();
|
||||
if (genericArguments.Length == 1 && genericArguments.Single().GenericParameterAttributes.HasFlag(GenericParameterAttributes.Contravariant))
|
||||
{
|
||||
var argument = service.GetGenericArguments().Single();
|
||||
var matches =
|
||||
bindings.Where(
|
||||
kvp =>
|
||||
kvp.Key.IsGenericType && kvp.Key.GetGenericTypeDefinition() == genericType && kvp.Key.GetGenericArguments().Single() != argument
|
||||
&& kvp.Key.GetGenericArguments().Single().IsAssignableFrom(argument)).SelectMany(kvp => kvp.Value);
|
||||
return matches;
|
||||
}
|
||||
}
|
||||
|
||||
return Enumerable.Empty<IBinding>();
|
||||
}
|
||||
}
|
||||
}
|
52
PlexRequests.UI/NinjectModules/MediatRModule.cs
Normal file
52
PlexRequests.UI/NinjectModules/MediatRModule.cs
Normal file
|
@ -0,0 +1,52 @@
|
|||
#region Copyright
|
||||
// /************************************************************************
|
||||
// Copyright (c) 2016 Jamie Rees
|
||||
// File: MediatRModule.cs
|
||||
// Created By: Jamie Rees
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person obtaining
|
||||
// a copy of this software and associated documentation files (the
|
||||
// "Software"), to deal in the Software without restriction, including
|
||||
// without limitation the rights to use, copy, modify, merge, publish,
|
||||
// distribute, sublicense, and/or sell copies of the Software, and to
|
||||
// permit persons to whom the Software is furnished to do so, subject to
|
||||
// the following conditions:
|
||||
//
|
||||
// The above copyright notice and this permission notice shall be
|
||||
// included in all copies or substantial portions of the Software.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
||||
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
||||
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
||||
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
||||
// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
||||
// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
||||
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
// ************************************************************************/
|
||||
#endregion
|
||||
using MediatR;
|
||||
|
||||
using Ninject;
|
||||
using Ninject.Extensions.Conventions;
|
||||
using Ninject.Modules;
|
||||
|
||||
namespace PlexRequests.UI.NinjectModules
|
||||
{
|
||||
public class MediatRModule : NinjectModule
|
||||
{
|
||||
public override void Load()
|
||||
{
|
||||
Kernel.Bind(scan => scan.FromAssemblyContaining<IMediator>().SelectAllClasses().BindDefaultInterface());
|
||||
|
||||
Bind<SingleInstanceFactory>().ToMethod(ctx => t => ctx.Kernel.Get(t));
|
||||
Bind<MultiInstanceFactory>().ToMethod(ctx => t => ctx.Kernel.GetAll(t));
|
||||
|
||||
Kernel.Bind(x => x.FromThisAssembly()
|
||||
.SelectAllClasses()
|
||||
.InheritedFromAny(typeof(IRequestHandler<,>), typeof(IAsyncRequestHandler<,>))
|
||||
.BindDefaultInterfaces());
|
||||
|
||||
//kernel.Bind(scan => scan.FromAssemblyContaining<LandingPageCommand>().SelectAllInterfaces().BindAllInterfaces());
|
||||
}
|
||||
}
|
||||
}
|
|
@ -73,12 +73,16 @@
|
|||
<HintPath>..\packages\Nancy.Swagger.0.1.0-alpha3\lib\net40\Nancy.Swagger.dll</HintPath>
|
||||
<Private>True</Private>
|
||||
</Reference>
|
||||
<Reference Include="Ninject, Version=3.0.0.0, Culture=neutral, PublicKeyToken=c7192dc5380945e7, processorArchitecture=MSIL">
|
||||
<HintPath>..\packages\Ninject.3.0.1.10\lib\net45-full\Ninject.dll</HintPath>
|
||||
<Reference Include="Ninject, Version=3.2.0.0, Culture=neutral, PublicKeyToken=c7192dc5380945e7, processorArchitecture=MSIL">
|
||||
<HintPath>..\packages\Ninject.3.2.0.0\lib\net45-full\Ninject.dll</HintPath>
|
||||
<Private>True</Private>
|
||||
</Reference>
|
||||
<Reference Include="Ninject.Extensions.ChildKernel, Version=3.0.0.0, Culture=neutral, PublicKeyToken=c7192dc5380945e7, processorArchitecture=MSIL">
|
||||
<HintPath>..\packages\Ninject.Extensions.ChildKernel.3.0.0.5\lib\net45-full\Ninject.Extensions.ChildKernel.dll</HintPath>
|
||||
<Reference Include="Ninject.Extensions.ChildKernel, Version=3.2.0.0, Culture=neutral, PublicKeyToken=c7192dc5380945e7, processorArchitecture=MSIL">
|
||||
<HintPath>..\packages\Ninject.Extensions.ChildKernel.3.2.0.0\lib\net45-full\Ninject.Extensions.ChildKernel.dll</HintPath>
|
||||
<Private>True</Private>
|
||||
</Reference>
|
||||
<Reference Include="Ninject.Extensions.Conventions, Version=3.2.0.0, Culture=neutral, PublicKeyToken=c7192dc5380945e7, processorArchitecture=MSIL">
|
||||
<HintPath>..\packages\Ninject.Extensions.Conventions.3.2.0.0\lib\net45-full\Ninject.Extensions.Conventions.dll</HintPath>
|
||||
<Private>True</Private>
|
||||
</Reference>
|
||||
<Reference Include="NLog, Version=4.0.0.0, Culture=neutral, PublicKeyToken=5120e14c03d0593c, processorArchitecture=MSIL">
|
||||
|
@ -175,6 +179,7 @@
|
|||
<ItemGroup>
|
||||
<Compile Include="Bootstrapper.cs" />
|
||||
<Compile Include="Helpers\BaseUrlHelper.cs" />
|
||||
<Compile Include="Helpers\ContravariantBindingResolver.cs" />
|
||||
<Compile Include="Helpers\CultureHelper.cs" />
|
||||
<Compile Include="Helpers\HeadphonesSender.cs" />
|
||||
<Compile Include="Helpers\EmptyViewBase.cs" />
|
||||
|
@ -221,6 +226,7 @@
|
|||
<Compile Include="NinjectModules\ApiModule.cs" />
|
||||
<Compile Include="NinjectModules\ConfigurationModule.cs" />
|
||||
<Compile Include="NinjectModules\DependancyResolver.cs" />
|
||||
<Compile Include="NinjectModules\MediatRModule.cs" />
|
||||
<Compile Include="NinjectModules\RepositoryModule.cs" />
|
||||
<Compile Include="NinjectModules\ServicesModule.cs" />
|
||||
<Compile Include="NinjectModules\SettingServiceModule.cs" />
|
||||
|
|
|
@ -26,9 +26,12 @@
|
|||
#endregion
|
||||
using System;
|
||||
|
||||
using MediatR;
|
||||
|
||||
using Nancy.TinyIoc;
|
||||
|
||||
using Ninject;
|
||||
using Ninject.Extensions.Conventions;
|
||||
using Ninject.Modules;
|
||||
using Ninject.Planning.Bindings.Resolvers;
|
||||
|
||||
|
@ -54,22 +57,9 @@ namespace PlexRequests.UI
|
|||
var modules = resolver.GetModules();
|
||||
var kernel = new StandardKernel(modules);
|
||||
|
||||
//kernel.Bind(x => x.FromThisAssembly()
|
||||
// .SelectAllClasses()
|
||||
// .InheritedFromAny(
|
||||
// new[]
|
||||
// {
|
||||
// typeof(IRequestHandler<,>),
|
||||
// typeof(IAsyncRequestHandler<,>),
|
||||
// })
|
||||
// .BindDefaultInterfaces());
|
||||
kernel.Components.Add<IBindingResolver, ContravariantBindingResolver>();
|
||||
|
||||
//kernel.Components.Add<IBindingResolver, ContravariantBindingResolver>();
|
||||
//kernel.Bind(scan => scan.FromAssemblyContaining<IMediator>().SelectAllClasses().BindDefaultInterface());
|
||||
//kernel.Bind(scan => scan.FromAssemblyContaining<LandingPageCommand>().SelectAllInterfaces().BindAllInterfaces());
|
||||
|
||||
//kernel.Bind<SingleInstanceFactory>().ToMethod(ctx => t => ctx.Kernel.Get(t));
|
||||
//kernel.Bind<MultiInstanceFactory>().ToMethod(ctx => t => ctx.Kernel.GetAll(t));
|
||||
|
||||
|
||||
app.UseNancy(options => options.Bootstrapper = new Bootstrapper(kernel));
|
||||
var scheduler = new Scheduler();
|
||||
|
|
|
@ -39,6 +39,14 @@
|
|||
<assemblyIdentity name="System.Data.SQLite" publicKeyToken="db937bc2d44ff139" culture="neutral" />
|
||||
<bindingRedirect oldVersion="0.0.0.0-1.0.99.0" newVersion="1.0.99.0" />
|
||||
</dependentAssembly>
|
||||
<dependentAssembly>
|
||||
<assemblyIdentity name="Ninject" publicKeyToken="c7192dc5380945e7" culture="neutral" />
|
||||
<bindingRedirect oldVersion="0.0.0.0-3.2.0.0" newVersion="3.2.0.0" />
|
||||
</dependentAssembly>
|
||||
<dependentAssembly>
|
||||
<assemblyIdentity name="Ninject.Extensions.ChildKernel" publicKeyToken="c7192dc5380945e7" culture="neutral" />
|
||||
<bindingRedirect oldVersion="0.0.0.0-3.2.0.0" newVersion="3.2.0.0" />
|
||||
</dependentAssembly>
|
||||
</assemblyBinding>
|
||||
</runtime>
|
||||
<system.web.webPages.razor>
|
||||
|
|
|
@ -29,8 +29,9 @@
|
|||
<package id="Nancy.Validation.FluentValidation" version="1.4.1" targetFramework="net45" />
|
||||
<package id="Nancy.Viewengines.Razor" version="1.4.1" targetFramework="net45" />
|
||||
<package id="Newtonsoft.Json" version="8.0.2" targetFramework="net45" />
|
||||
<package id="Ninject" version="3.0.1.10" targetFramework="net45" />
|
||||
<package id="Ninject.Extensions.ChildKernel" version="3.0.0.5" targetFramework="net45" />
|
||||
<package id="Ninject" version="3.2.0.0" targetFramework="net45" />
|
||||
<package id="Ninject.Extensions.ChildKernel" version="3.2.0.0" targetFramework="net45" />
|
||||
<package id="Ninject.Extensions.Conventions" version="3.2.0.0" targetFramework="net45" />
|
||||
<package id="NLog" version="4.3.4" targetFramework="net45" />
|
||||
<package id="NLog.Config" version="4.2.3" targetFramework="net45" />
|
||||
<package id="NLog.Schema" version="4.0.0" targetFramework="net45" />
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue