/
ExtensionsForIKernel.cs
65 lines (61 loc) · 2.53 KB
/
ExtensionsForIKernel.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
// -------------------------------------------------------------------------------------------------
// <copyright file="ExtensionsForIKernel.cs" company="Ninject Project Contributors">
// Copyright (c) 2009-2017 Ninject Project Contributors. All rights reserved.
//
// Dual-licensed under the Apache License, Version 2.0, and the Microsoft Public License (Ms-PL).
// You may not use this file except in compliance with one of the Licenses.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
// or
// http://www.microsoft.com/opensource/licenses.mspx
//
// 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.
// </copyright>
// -------------------------------------------------------------------------------------------------
namespace Ninject.Extensions.Conventions
{
using System;
using Ninject.Extensions.Conventions.BindingBuilder;
using Ninject.Extensions.Conventions.BindingGenerators;
using Ninject.Extensions.Conventions.Syntax;
using Ninject.Infrastructure;
using Ninject.Modules;
using Ninject.Syntax;
/// <summary>
/// Provides extensions for the IKernel interface
/// </summary>
public static class ExtensionsForIKernel
{
/// <summary>
/// Creates bindings using conventions
/// </summary>
/// <param name="kernel">The kernel for which the bindings are created.</param>
/// <param name="configure">The binding convention configuration.</param>
public static void Bind(this IBindingRoot kernel, Action<IFromSyntax> configure)
{
if (configure == null)
{
throw new ArgumentNullException("configure");
}
var assemblyNameRetriever = new AssemblyNameRetriever();
try
{
var builder = new ConventionSyntax(
new ConventionBindingBuilder(kernel, new TypeSelector()),
new AssemblyFinder(assemblyNameRetriever),
new TypeFilter(),
new BindingGeneratorFactory(new BindableTypeSelector()));
configure(builder);
}
finally
{
assemblyNameRetriever.Dispose();
}
}
}
}