-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #3 from warquys/ReviewNinjecet
Review ninjecet
- Loading branch information
Showing
16 changed files
with
105 additions
and
2 deletions.
There are no files selected for viewing
Binary file not shown.
Binary file removed
BIN
-43.6 KB
.vs/Neuron/FileContentIndex/210ea504-560e-4d60-94cd-02411a0946b4.vsidx
Binary file not shown.
Binary file removed
BIN
-16.3 KB
.vs/Neuron/FileContentIndex/85cc93fd-a7b7-4bd0-b050-09cae2e6290a.vsidx
Binary file not shown.
Binary file removed
BIN
-16.3 KB
.vs/Neuron/FileContentIndex/e268a164-c69f-478d-b06c-24869b03a1d9.vsidx
Binary file not shown.
Empty file.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
This file contains 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 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,76 @@ | ||
using Ninject.Activation.Providers; | ||
using Ninject.Activation; | ||
using Ninject.Components; | ||
using Ninject.Infrastructure; | ||
using Ninject.Planning.Bindings; | ||
using Ninject.Planning.Bindings.Resolvers; | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
|
||
namespace Neuron.Core; | ||
|
||
public class NullableBindingResolver : NinjectComponent, IMissingBindingResolver, INinjectComponent, IDisposable | ||
{ | ||
public class NullProvider : IProvider | ||
{ | ||
public NullProvider(Type prototype) | ||
{ | ||
Type = prototype; | ||
} | ||
|
||
public Type Type { get; private set; } | ||
|
||
public object Create(IContext context) => null; | ||
} | ||
|
||
/// <summary> | ||
/// Returns any bindings from the specified collection that match the specified service. | ||
/// </summary> | ||
/// <param name="bindings"> | ||
/// The multimap of all registered bindings. | ||
/// </param> | ||
/// <param name="request"> | ||
/// The series of matching bindings. | ||
/// </param> | ||
/// <returns> | ||
/// The series of matching bindings. | ||
/// </returns> | ||
public IEnumerable<IBinding> Resolve(Multimap<Type, IBinding> bindings, IRequest request) | ||
{ | ||
var service = request.Service; | ||
if (!TypeIsSelfBindable(service)) | ||
{ | ||
return Enumerable.Empty<IBinding>(); | ||
} | ||
|
||
var provider = new NullProvider(service); | ||
|
||
return new Binding[1] | ||
{ | ||
new Binding(service) | ||
{ | ||
ProviderCallback = (IContext _) => provider | ||
} | ||
}; | ||
} | ||
|
||
/// <summary> | ||
/// Returns a value indicating whether the specified service is self-bindable. | ||
/// </summary> | ||
/// <param name="service"> | ||
/// The service. | ||
/// </param> | ||
/// <returns> | ||
/// True if the type is self-bindable; otherwise false. | ||
/// </returns> | ||
protected virtual bool TypeIsSelfBindable(Type service) | ||
{ | ||
if (!service.IsInterface && !service.IsAbstract && !service.IsValueType && service != typeof(string)) | ||
{ | ||
return !service.ContainsGenericParameters; | ||
} | ||
|
||
return false; | ||
} | ||
} |
This file contains 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 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 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 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