diff --git a/Ninject.sln b/Ninject.sln
index 8d742595..70d7c310 100644
--- a/Ninject.sln
+++ b/Ninject.sln
@@ -5,201 +5,41 @@ VisualStudioVersion = 14.0.25420.1
MinimumVisualStudioVersion = 10.0.40219.1
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution Items", "{3E299B94-5F07-49DE-8226-55EDC56F13E3}"
ProjectSection(SolutionItems) = preProject
- Portable.Ninject.nuspec = Portable.Ninject.nuspec
+ global.json = global.json
EndProjectSection
EndProject
-Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Ninject", "src\Ninject\Ninject.csproj", "{ADF369E2-6B9E-4D56-9B82-D273AE41EC2D}"
+Project("{8BB2217D-0F2D-49D1-97BC-3654ED321F3B}") = "Ninject", "src\Ninject\Ninject.xproj", "{ADF369E2-6B9E-4D56-9B82-D273AE41EC2D}"
EndProject
-Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "CommonServiceLocator.NinjectAdapter", "src\CommonServiceLocator.NinjectAdapter\CommonServiceLocator.NinjectAdapter.csproj", "{9BD94717-484B-4EB1-AF32-8D4244F02E8E}"
+Project("{8BB2217D-0F2D-49D1-97BC-3654ED321F3B}") = "Ninject.Tests", "src\Ninject.Test\Ninject.Tests.xproj", "{7E7DE343-8DBD-42EE-94ED-036E9E0F5411}"
EndProject
-Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Ninject.Tests", "src\Ninject.Test\Ninject.Tests.csproj", "{7E7DE343-8DBD-42EE-94ED-036E9E0F5411}"
+Project("{8BB2217D-0F2D-49D1-97BC-3654ED321F3B}") = "TestAssembly", "src\TestAssembly\TestAssembly.xproj", "{C9F6CFE7-44B2-4D55-9307-33C34C045468}"
EndProject
-Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "TestModules", "src\TestModules\TestModules.csproj", "{90F46524-0716-4180-8A5F-1CD1EB5686F6}"
-EndProject
-Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "TestAssembly", "src\TestAssembly\TestAssembly.csproj", "{C9F6CFE7-44B2-4D55-9307-33C34C045468}"
-EndProject
-Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "CommonServiceLocator.NinjectAdapter.Tests", "src\CommonServiceLocator.NinjectAdapter.Tests\CommonServiceLocator.NinjectAdapter.Tests.csproj", "{3B703A23-DB64-4606-B124-16BA83C461B2}"
-EndProject
-Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Tests", "Tests", "{F1218241-9ED7-4DFA-9943-868AF26365CC}"
-EndProject
-Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "RemotingTestServer", "RemotingServer\RemotingTestServer.csproj", "{E2FCFE04-2D57-4F43-8E13-12B47B878C18}"
-EndProject
-Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "RemotingTestClient", "RemotingTestClient\RemotingTestClient.csproj", "{0BAD25A0-BE8E-4D8F-9EB2-AB7B307B9D94}"
-EndProject
-Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Ninject.Net45", "src\Ninject\Ninject.Net45.csproj", "{37AAD36A-2252-43D6-8BC4-F63BFEFDFECB}"
+Project("{8BB2217D-0F2D-49D1-97BC-3654ED321F3B}") = "TestModules", "src\TestModules\TestModules.xproj", "{90F46524-0716-4180-8A5F-1CD1EB5686F6}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
- Debug|ARM = Debug|ARM
- Debug|iPhone = Debug|iPhone
- Debug|iPhoneSimulator = Debug|iPhoneSimulator
- Debug|Mixed Platforms = Debug|Mixed Platforms
- Debug|x86 = Debug|x86
Release|Any CPU = Release|Any CPU
- Release|ARM = Release|ARM
- Release|iPhone = Release|iPhone
- Release|iPhoneSimulator = Release|iPhoneSimulator
- Release|Mixed Platforms = Release|Mixed Platforms
- Release|x86 = Release|x86
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{ADF369E2-6B9E-4D56-9B82-D273AE41EC2D}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{ADF369E2-6B9E-4D56-9B82-D273AE41EC2D}.Debug|Any CPU.Build.0 = Debug|Any CPU
- {ADF369E2-6B9E-4D56-9B82-D273AE41EC2D}.Debug|ARM.ActiveCfg = Debug|Any CPU
- {ADF369E2-6B9E-4D56-9B82-D273AE41EC2D}.Debug|iPhone.ActiveCfg = Debug|Any CPU
- {ADF369E2-6B9E-4D56-9B82-D273AE41EC2D}.Debug|iPhoneSimulator.ActiveCfg = Debug|Any CPU
- {ADF369E2-6B9E-4D56-9B82-D273AE41EC2D}.Debug|Mixed Platforms.ActiveCfg = Debug|Any CPU
- {ADF369E2-6B9E-4D56-9B82-D273AE41EC2D}.Debug|Mixed Platforms.Build.0 = Debug|Any CPU
- {ADF369E2-6B9E-4D56-9B82-D273AE41EC2D}.Debug|x86.ActiveCfg = Debug|Any CPU
- {ADF369E2-6B9E-4D56-9B82-D273AE41EC2D}.Debug|x86.Build.0 = Debug|Any CPU
{ADF369E2-6B9E-4D56-9B82-D273AE41EC2D}.Release|Any CPU.ActiveCfg = Release|Any CPU
{ADF369E2-6B9E-4D56-9B82-D273AE41EC2D}.Release|Any CPU.Build.0 = Release|Any CPU
- {ADF369E2-6B9E-4D56-9B82-D273AE41EC2D}.Release|ARM.ActiveCfg = Release|Any CPU
- {ADF369E2-6B9E-4D56-9B82-D273AE41EC2D}.Release|iPhone.ActiveCfg = Release|Any CPU
- {ADF369E2-6B9E-4D56-9B82-D273AE41EC2D}.Release|iPhoneSimulator.ActiveCfg = Release|Any CPU
- {ADF369E2-6B9E-4D56-9B82-D273AE41EC2D}.Release|Mixed Platforms.ActiveCfg = Release|Any CPU
- {ADF369E2-6B9E-4D56-9B82-D273AE41EC2D}.Release|Mixed Platforms.Build.0 = Release|Any CPU
- {ADF369E2-6B9E-4D56-9B82-D273AE41EC2D}.Release|x86.ActiveCfg = Release|Any CPU
- {ADF369E2-6B9E-4D56-9B82-D273AE41EC2D}.Release|x86.Build.0 = Release|Any CPU
- {9BD94717-484B-4EB1-AF32-8D4244F02E8E}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
- {9BD94717-484B-4EB1-AF32-8D4244F02E8E}.Debug|Any CPU.Build.0 = Debug|Any CPU
- {9BD94717-484B-4EB1-AF32-8D4244F02E8E}.Debug|ARM.ActiveCfg = Debug|Any CPU
- {9BD94717-484B-4EB1-AF32-8D4244F02E8E}.Debug|iPhone.ActiveCfg = Debug|Any CPU
- {9BD94717-484B-4EB1-AF32-8D4244F02E8E}.Debug|iPhoneSimulator.ActiveCfg = Debug|Any CPU
- {9BD94717-484B-4EB1-AF32-8D4244F02E8E}.Debug|Mixed Platforms.ActiveCfg = Debug|Any CPU
- {9BD94717-484B-4EB1-AF32-8D4244F02E8E}.Debug|Mixed Platforms.Build.0 = Debug|Any CPU
- {9BD94717-484B-4EB1-AF32-8D4244F02E8E}.Debug|x86.ActiveCfg = Debug|Any CPU
- {9BD94717-484B-4EB1-AF32-8D4244F02E8E}.Release|Any CPU.ActiveCfg = Release|Any CPU
- {9BD94717-484B-4EB1-AF32-8D4244F02E8E}.Release|Any CPU.Build.0 = Release|Any CPU
- {9BD94717-484B-4EB1-AF32-8D4244F02E8E}.Release|ARM.ActiveCfg = Release|Any CPU
- {9BD94717-484B-4EB1-AF32-8D4244F02E8E}.Release|iPhone.ActiveCfg = Release|Any CPU
- {9BD94717-484B-4EB1-AF32-8D4244F02E8E}.Release|iPhoneSimulator.ActiveCfg = Release|Any CPU
- {9BD94717-484B-4EB1-AF32-8D4244F02E8E}.Release|Mixed Platforms.ActiveCfg = Release|Any CPU
- {9BD94717-484B-4EB1-AF32-8D4244F02E8E}.Release|Mixed Platforms.Build.0 = Release|Any CPU
- {9BD94717-484B-4EB1-AF32-8D4244F02E8E}.Release|x86.ActiveCfg = Release|Any CPU
{7E7DE343-8DBD-42EE-94ED-036E9E0F5411}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{7E7DE343-8DBD-42EE-94ED-036E9E0F5411}.Debug|Any CPU.Build.0 = Debug|Any CPU
- {7E7DE343-8DBD-42EE-94ED-036E9E0F5411}.Debug|ARM.ActiveCfg = Debug|Any CPU
- {7E7DE343-8DBD-42EE-94ED-036E9E0F5411}.Debug|iPhone.ActiveCfg = Debug|Any CPU
- {7E7DE343-8DBD-42EE-94ED-036E9E0F5411}.Debug|iPhoneSimulator.ActiveCfg = Debug|Any CPU
- {7E7DE343-8DBD-42EE-94ED-036E9E0F5411}.Debug|Mixed Platforms.ActiveCfg = Debug|Any CPU
- {7E7DE343-8DBD-42EE-94ED-036E9E0F5411}.Debug|Mixed Platforms.Build.0 = Debug|Any CPU
- {7E7DE343-8DBD-42EE-94ED-036E9E0F5411}.Debug|x86.ActiveCfg = Debug|Any CPU
{7E7DE343-8DBD-42EE-94ED-036E9E0F5411}.Release|Any CPU.ActiveCfg = Release|Any CPU
{7E7DE343-8DBD-42EE-94ED-036E9E0F5411}.Release|Any CPU.Build.0 = Release|Any CPU
- {7E7DE343-8DBD-42EE-94ED-036E9E0F5411}.Release|ARM.ActiveCfg = Release|Any CPU
- {7E7DE343-8DBD-42EE-94ED-036E9E0F5411}.Release|iPhone.ActiveCfg = Release|Any CPU
- {7E7DE343-8DBD-42EE-94ED-036E9E0F5411}.Release|iPhoneSimulator.ActiveCfg = Release|Any CPU
- {7E7DE343-8DBD-42EE-94ED-036E9E0F5411}.Release|Mixed Platforms.ActiveCfg = Release|Any CPU
- {7E7DE343-8DBD-42EE-94ED-036E9E0F5411}.Release|Mixed Platforms.Build.0 = Release|Any CPU
- {7E7DE343-8DBD-42EE-94ED-036E9E0F5411}.Release|x86.ActiveCfg = Release|Any CPU
- {90F46524-0716-4180-8A5F-1CD1EB5686F6}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
- {90F46524-0716-4180-8A5F-1CD1EB5686F6}.Debug|Any CPU.Build.0 = Debug|Any CPU
- {90F46524-0716-4180-8A5F-1CD1EB5686F6}.Debug|ARM.ActiveCfg = Debug|Any CPU
- {90F46524-0716-4180-8A5F-1CD1EB5686F6}.Debug|iPhone.ActiveCfg = Debug|Any CPU
- {90F46524-0716-4180-8A5F-1CD1EB5686F6}.Debug|iPhoneSimulator.ActiveCfg = Debug|Any CPU
- {90F46524-0716-4180-8A5F-1CD1EB5686F6}.Debug|Mixed Platforms.ActiveCfg = Debug|Any CPU
- {90F46524-0716-4180-8A5F-1CD1EB5686F6}.Debug|Mixed Platforms.Build.0 = Debug|Any CPU
- {90F46524-0716-4180-8A5F-1CD1EB5686F6}.Debug|x86.ActiveCfg = Debug|Any CPU
- {90F46524-0716-4180-8A5F-1CD1EB5686F6}.Release|Any CPU.ActiveCfg = Release|Any CPU
- {90F46524-0716-4180-8A5F-1CD1EB5686F6}.Release|Any CPU.Build.0 = Release|Any CPU
- {90F46524-0716-4180-8A5F-1CD1EB5686F6}.Release|ARM.ActiveCfg = Release|Any CPU
- {90F46524-0716-4180-8A5F-1CD1EB5686F6}.Release|iPhone.ActiveCfg = Release|Any CPU
- {90F46524-0716-4180-8A5F-1CD1EB5686F6}.Release|iPhoneSimulator.ActiveCfg = Release|Any CPU
- {90F46524-0716-4180-8A5F-1CD1EB5686F6}.Release|Mixed Platforms.ActiveCfg = Release|Any CPU
- {90F46524-0716-4180-8A5F-1CD1EB5686F6}.Release|Mixed Platforms.Build.0 = Release|Any CPU
- {90F46524-0716-4180-8A5F-1CD1EB5686F6}.Release|x86.ActiveCfg = Release|Any CPU
{C9F6CFE7-44B2-4D55-9307-33C34C045468}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{C9F6CFE7-44B2-4D55-9307-33C34C045468}.Debug|Any CPU.Build.0 = Debug|Any CPU
- {C9F6CFE7-44B2-4D55-9307-33C34C045468}.Debug|ARM.ActiveCfg = Debug|Any CPU
- {C9F6CFE7-44B2-4D55-9307-33C34C045468}.Debug|iPhone.ActiveCfg = Debug|Any CPU
- {C9F6CFE7-44B2-4D55-9307-33C34C045468}.Debug|iPhoneSimulator.ActiveCfg = Debug|Any CPU
- {C9F6CFE7-44B2-4D55-9307-33C34C045468}.Debug|Mixed Platforms.ActiveCfg = Debug|Any CPU
- {C9F6CFE7-44B2-4D55-9307-33C34C045468}.Debug|Mixed Platforms.Build.0 = Debug|Any CPU
- {C9F6CFE7-44B2-4D55-9307-33C34C045468}.Debug|x86.ActiveCfg = Debug|Any CPU
{C9F6CFE7-44B2-4D55-9307-33C34C045468}.Release|Any CPU.ActiveCfg = Release|Any CPU
{C9F6CFE7-44B2-4D55-9307-33C34C045468}.Release|Any CPU.Build.0 = Release|Any CPU
- {C9F6CFE7-44B2-4D55-9307-33C34C045468}.Release|ARM.ActiveCfg = Release|Any CPU
- {C9F6CFE7-44B2-4D55-9307-33C34C045468}.Release|iPhone.ActiveCfg = Release|Any CPU
- {C9F6CFE7-44B2-4D55-9307-33C34C045468}.Release|iPhoneSimulator.ActiveCfg = Release|Any CPU
- {C9F6CFE7-44B2-4D55-9307-33C34C045468}.Release|Mixed Platforms.ActiveCfg = Release|Any CPU
- {C9F6CFE7-44B2-4D55-9307-33C34C045468}.Release|Mixed Platforms.Build.0 = Release|Any CPU
- {C9F6CFE7-44B2-4D55-9307-33C34C045468}.Release|x86.ActiveCfg = Release|Any CPU
- {3B703A23-DB64-4606-B124-16BA83C461B2}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
- {3B703A23-DB64-4606-B124-16BA83C461B2}.Debug|Any CPU.Build.0 = Debug|Any CPU
- {3B703A23-DB64-4606-B124-16BA83C461B2}.Debug|ARM.ActiveCfg = Debug|Any CPU
- {3B703A23-DB64-4606-B124-16BA83C461B2}.Debug|iPhone.ActiveCfg = Debug|Any CPU
- {3B703A23-DB64-4606-B124-16BA83C461B2}.Debug|iPhoneSimulator.ActiveCfg = Debug|Any CPU
- {3B703A23-DB64-4606-B124-16BA83C461B2}.Debug|Mixed Platforms.ActiveCfg = Debug|Any CPU
- {3B703A23-DB64-4606-B124-16BA83C461B2}.Debug|Mixed Platforms.Build.0 = Debug|Any CPU
- {3B703A23-DB64-4606-B124-16BA83C461B2}.Debug|x86.ActiveCfg = Debug|Any CPU
- {3B703A23-DB64-4606-B124-16BA83C461B2}.Release|Any CPU.ActiveCfg = Release|Any CPU
- {3B703A23-DB64-4606-B124-16BA83C461B2}.Release|Any CPU.Build.0 = Release|Any CPU
- {3B703A23-DB64-4606-B124-16BA83C461B2}.Release|ARM.ActiveCfg = Release|Any CPU
- {3B703A23-DB64-4606-B124-16BA83C461B2}.Release|iPhone.ActiveCfg = Release|Any CPU
- {3B703A23-DB64-4606-B124-16BA83C461B2}.Release|iPhoneSimulator.ActiveCfg = Release|Any CPU
- {3B703A23-DB64-4606-B124-16BA83C461B2}.Release|Mixed Platforms.ActiveCfg = Release|Any CPU
- {3B703A23-DB64-4606-B124-16BA83C461B2}.Release|Mixed Platforms.Build.0 = Release|Any CPU
- {3B703A23-DB64-4606-B124-16BA83C461B2}.Release|x86.ActiveCfg = Release|Any CPU
- {E2FCFE04-2D57-4F43-8E13-12B47B878C18}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
- {E2FCFE04-2D57-4F43-8E13-12B47B878C18}.Debug|Any CPU.Build.0 = Debug|Any CPU
- {E2FCFE04-2D57-4F43-8E13-12B47B878C18}.Debug|ARM.ActiveCfg = Debug|Any CPU
- {E2FCFE04-2D57-4F43-8E13-12B47B878C18}.Debug|iPhone.ActiveCfg = Debug|Any CPU
- {E2FCFE04-2D57-4F43-8E13-12B47B878C18}.Debug|iPhoneSimulator.ActiveCfg = Debug|Any CPU
- {E2FCFE04-2D57-4F43-8E13-12B47B878C18}.Debug|Mixed Platforms.ActiveCfg = Debug|Any CPU
- {E2FCFE04-2D57-4F43-8E13-12B47B878C18}.Debug|Mixed Platforms.Build.0 = Debug|Any CPU
- {E2FCFE04-2D57-4F43-8E13-12B47B878C18}.Debug|x86.ActiveCfg = Debug|Any CPU
- {E2FCFE04-2D57-4F43-8E13-12B47B878C18}.Release|Any CPU.ActiveCfg = Release|Any CPU
- {E2FCFE04-2D57-4F43-8E13-12B47B878C18}.Release|Any CPU.Build.0 = Release|Any CPU
- {E2FCFE04-2D57-4F43-8E13-12B47B878C18}.Release|ARM.ActiveCfg = Release|Any CPU
- {E2FCFE04-2D57-4F43-8E13-12B47B878C18}.Release|iPhone.ActiveCfg = Release|Any CPU
- {E2FCFE04-2D57-4F43-8E13-12B47B878C18}.Release|iPhoneSimulator.ActiveCfg = Release|Any CPU
- {E2FCFE04-2D57-4F43-8E13-12B47B878C18}.Release|Mixed Platforms.ActiveCfg = Release|Any CPU
- {E2FCFE04-2D57-4F43-8E13-12B47B878C18}.Release|Mixed Platforms.Build.0 = Release|Any CPU
- {E2FCFE04-2D57-4F43-8E13-12B47B878C18}.Release|x86.ActiveCfg = Release|Any CPU
- {0BAD25A0-BE8E-4D8F-9EB2-AB7B307B9D94}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
- {0BAD25A0-BE8E-4D8F-9EB2-AB7B307B9D94}.Debug|Any CPU.Build.0 = Debug|Any CPU
- {0BAD25A0-BE8E-4D8F-9EB2-AB7B307B9D94}.Debug|ARM.ActiveCfg = Debug|Any CPU
- {0BAD25A0-BE8E-4D8F-9EB2-AB7B307B9D94}.Debug|iPhone.ActiveCfg = Debug|Any CPU
- {0BAD25A0-BE8E-4D8F-9EB2-AB7B307B9D94}.Debug|iPhoneSimulator.ActiveCfg = Debug|Any CPU
- {0BAD25A0-BE8E-4D8F-9EB2-AB7B307B9D94}.Debug|Mixed Platforms.ActiveCfg = Debug|Any CPU
- {0BAD25A0-BE8E-4D8F-9EB2-AB7B307B9D94}.Debug|Mixed Platforms.Build.0 = Debug|Any CPU
- {0BAD25A0-BE8E-4D8F-9EB2-AB7B307B9D94}.Debug|x86.ActiveCfg = Debug|Any CPU
- {0BAD25A0-BE8E-4D8F-9EB2-AB7B307B9D94}.Release|Any CPU.ActiveCfg = Release|Any CPU
- {0BAD25A0-BE8E-4D8F-9EB2-AB7B307B9D94}.Release|Any CPU.Build.0 = Release|Any CPU
- {0BAD25A0-BE8E-4D8F-9EB2-AB7B307B9D94}.Release|ARM.ActiveCfg = Release|Any CPU
- {0BAD25A0-BE8E-4D8F-9EB2-AB7B307B9D94}.Release|iPhone.ActiveCfg = Release|Any CPU
- {0BAD25A0-BE8E-4D8F-9EB2-AB7B307B9D94}.Release|iPhoneSimulator.ActiveCfg = Release|Any CPU
- {0BAD25A0-BE8E-4D8F-9EB2-AB7B307B9D94}.Release|Mixed Platforms.ActiveCfg = Release|Any CPU
- {0BAD25A0-BE8E-4D8F-9EB2-AB7B307B9D94}.Release|Mixed Platforms.Build.0 = Release|Any CPU
- {0BAD25A0-BE8E-4D8F-9EB2-AB7B307B9D94}.Release|x86.ActiveCfg = Release|Any CPU
- {37AAD36A-2252-43D6-8BC4-F63BFEFDFECB}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
- {37AAD36A-2252-43D6-8BC4-F63BFEFDFECB}.Debug|Any CPU.Build.0 = Debug|Any CPU
- {37AAD36A-2252-43D6-8BC4-F63BFEFDFECB}.Debug|ARM.ActiveCfg = Debug|Any CPU
- {37AAD36A-2252-43D6-8BC4-F63BFEFDFECB}.Debug|iPhone.ActiveCfg = Debug|Any CPU
- {37AAD36A-2252-43D6-8BC4-F63BFEFDFECB}.Debug|iPhoneSimulator.ActiveCfg = Debug|Any CPU
- {37AAD36A-2252-43D6-8BC4-F63BFEFDFECB}.Debug|Mixed Platforms.ActiveCfg = Debug|Any CPU
- {37AAD36A-2252-43D6-8BC4-F63BFEFDFECB}.Debug|Mixed Platforms.Build.0 = Debug|Any CPU
- {37AAD36A-2252-43D6-8BC4-F63BFEFDFECB}.Debug|x86.ActiveCfg = Debug|Any CPU
- {37AAD36A-2252-43D6-8BC4-F63BFEFDFECB}.Release|Any CPU.ActiveCfg = Release|Any CPU
- {37AAD36A-2252-43D6-8BC4-F63BFEFDFECB}.Release|Any CPU.Build.0 = Release|Any CPU
- {37AAD36A-2252-43D6-8BC4-F63BFEFDFECB}.Release|ARM.ActiveCfg = Release|Any CPU
- {37AAD36A-2252-43D6-8BC4-F63BFEFDFECB}.Release|iPhone.ActiveCfg = Release|Any CPU
- {37AAD36A-2252-43D6-8BC4-F63BFEFDFECB}.Release|iPhoneSimulator.ActiveCfg = Release|Any CPU
- {37AAD36A-2252-43D6-8BC4-F63BFEFDFECB}.Release|Mixed Platforms.ActiveCfg = Release|Any CPU
- {37AAD36A-2252-43D6-8BC4-F63BFEFDFECB}.Release|Mixed Platforms.Build.0 = Release|Any CPU
- {37AAD36A-2252-43D6-8BC4-F63BFEFDFECB}.Release|x86.ActiveCfg = Release|Any CPU
+ {90F46524-0716-4180-8A5F-1CD1EB5686F6}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
+ {90F46524-0716-4180-8A5F-1CD1EB5686F6}.Debug|Any CPU.Build.0 = Debug|Any CPU
+ {90F46524-0716-4180-8A5F-1CD1EB5686F6}.Release|Any CPU.ActiveCfg = Release|Any CPU
+ {90F46524-0716-4180-8A5F-1CD1EB5686F6}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
- GlobalSection(NestedProjects) = preSolution
- {7E7DE343-8DBD-42EE-94ED-036E9E0F5411} = {F1218241-9ED7-4DFA-9943-868AF26365CC}
- {90F46524-0716-4180-8A5F-1CD1EB5686F6} = {F1218241-9ED7-4DFA-9943-868AF26365CC}
- {C9F6CFE7-44B2-4D55-9307-33C34C045468} = {F1218241-9ED7-4DFA-9943-868AF26365CC}
- {3B703A23-DB64-4606-B124-16BA83C461B2} = {F1218241-9ED7-4DFA-9943-868AF26365CC}
- {E2FCFE04-2D57-4F43-8E13-12B47B878C18} = {F1218241-9ED7-4DFA-9943-868AF26365CC}
- {0BAD25A0-BE8E-4D8F-9EB2-AB7B307B9D94} = {F1218241-9ED7-4DFA-9943-868AF26365CC}
- EndGlobalSection
EndGlobal
diff --git a/global.json b/global.json
new file mode 100644
index 00000000..1d766907
--- /dev/null
+++ b/global.json
@@ -0,0 +1,6 @@
+{
+ "projects": [ "src" ],
+ "sdk": {
+ "version": "1.0.0-preview2-003121"
+ }
+}
\ No newline at end of file
diff --git a/src/Ninject.Test/Ninject.Tests.WinRT_TemporaryKey.pfx b/src/Ninject.Test/Ninject.Tests.WinRT_TemporaryKey.pfx
deleted file mode 100644
index 317f3a14..00000000
Binary files a/src/Ninject.Test/Ninject.Tests.WinRT_TemporaryKey.pfx and /dev/null differ
diff --git a/src/Ninject.Test/Ninject.Tests.xproj b/src/Ninject.Test/Ninject.Tests.xproj
new file mode 100644
index 00000000..d22c3235
--- /dev/null
+++ b/src/Ninject.Test/Ninject.Tests.xproj
@@ -0,0 +1,22 @@
+
+
+
+ 14.0
+ $(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion)
+
+
+
+ 7e7de343-8dbd-42ee-94ed-036e9e0f5411
+ Ninject.Tests
+ .\obj
+ .\bin\
+ v4.5.2
+
+
+ 2.0
+
+
+
+
+
+
\ No newline at end of file
diff --git a/src/Ninject.Test/Package.appxmanifest b/src/Ninject.Test/Package.appxmanifest
deleted file mode 100644
index ac6f076c..00000000
--- a/src/Ninject.Test/Package.appxmanifest
+++ /dev/null
@@ -1,29 +0,0 @@
-
-
-
-
- Ninject.Tests
- Oren
- Images\UnitTestStoreLogo.png
- Ninject.Tests
-
-
- 6.3.0
- 6.3.0
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
\ No newline at end of file
diff --git a/src/Ninject.Test/Settings.StyleCop b/src/Ninject.Test/Settings.StyleCop
deleted file mode 100644
index 46cee62b..00000000
--- a/src/Ninject.Test/Settings.StyleCop
+++ /dev/null
@@ -1,19 +0,0 @@
-
-
-
-
-
-
- False
-
-
-
-
- False
-
-
-
-
-
-
-
\ No newline at end of file
diff --git a/src/Ninject.Test/project.json b/src/Ninject.Test/project.json
new file mode 100644
index 00000000..245a4f6d
--- /dev/null
+++ b/src/Ninject.Test/project.json
@@ -0,0 +1,18 @@
+{
+ "version": "1.0.0-*",
+ "testRunner": "xunit",
+ "dependencies": {
+ "Moq": "4.5.8",
+ "Ninject": "4.0.0-beta",
+ "TestAssembly": "1.0.0",
+ "TestModules": "1.0.0",
+ "xunit": "2.2.0-beta2-build3300",
+ "dotnet-test-xunit": "2.2.0-preview2-build1029",
+ "FluentAssertions": "4.6.3"
+ },
+ "buildOptions": { "copyToOutput": "TestModules\\*" },
+ "frameworks": {
+ "net451": {
+ }
+ }
+}
\ No newline at end of file
diff --git a/src/Ninject/Activation/Blocks/ActivationBlock.cs b/src/Ninject/Activation/Blocks/ActivationBlock.cs
index 8b561cb8..f161c5c8 100644
--- a/src/Ninject/Activation/Blocks/ActivationBlock.cs
+++ b/src/Ninject/Activation/Blocks/ActivationBlock.cs
@@ -1,67 +1,56 @@
-#region License
-//
-// Author: Nate Kohari
-// Copyright (c) 2007-2010, Enkari, Ltd.
-//
-// Dual-licensed under the Apache License, Version 2.0, and the Microsoft Public License (Ms-PL).
-// See the file LICENSE.txt for details.
-//
-#endregion
-#region Using Directives
-using System;
-using System.Collections.Generic;
-using Ninject.Infrastructure;
-using Ninject.Infrastructure.Disposal;
-using Ninject.Parameters;
-using Ninject.Planning.Bindings;
-using Ninject.Syntax;
-#endregion
+//-------------------------------------------------------------------------------------------------
+//
+// Copyright (c) 2007-2010, Enkari, Ltd.
+// Copyright (c) 2010-2016, Ninject Project Contributors
+// Authors: Nate Kohari (nate@enkari.com)
+// Remo Gloor (remo.gloor@gmail.com)
+//
+// 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.
+//
+//-------------------------------------------------------------------------------------------------
namespace Ninject.Activation.Blocks
{
+ using System;
+ using System.Collections.Generic;
+ using System.Diagnostics.Contracts;
+ using Ninject.Infrastructure.Disposal;
+ using Ninject.Parameters;
+ using Ninject.Planning.Bindings;
+ using Ninject.Syntax;
+
///
/// A block used for deterministic disposal of activated instances. When the block is
/// disposed, all instances activated via it will be deactivated.
///
public class ActivationBlock : DisposableObject, IActivationBlock
{
- ///
- /// Gets or sets the parent resolution root (usually the kernel).
- ///
- public IResolutionRoot Parent { get; private set; }
-
- ///
- /// Occurs when the object is disposed.
- ///
- public event EventHandler Disposed;
-
///
/// Initializes a new instance of the class.
///
/// The parent resolution root.
public ActivationBlock(IResolutionRoot parent)
{
- Ensure.ArgumentNotNull(parent, "parent");
- Parent = parent;
+ Contract.Requires(parent != null);
+ this.Parent = parent;
}
///
- /// Releases resources held by the object.
+ /// Gets the parent resolution root (usually the kernel).
///
- public override void Dispose(bool disposing)
- {
- lock (this)
- {
- if (disposing && !IsDisposed)
- {
- var evt = Disposed;
- if (evt != null) evt(this, EventArgs.Empty);
- Disposed = null;
- }
-
- base.Dispose(disposing);
- }
- }
+ public IResolutionRoot Parent { get; private set; }
///
/// Injects the specified existing instance, without managing its lifecycle.
@@ -70,7 +59,7 @@ public override void Dispose(bool disposing)
/// The parameters to pass to the request.
public void Inject(object instance, params IParameter[] parameters)
{
- Parent.Inject(instance, parameters);
+ this.Parent.Inject(instance, parameters);
}
///
@@ -80,7 +69,7 @@ public void Inject(object instance, params IParameter[] parameters)
/// True if the request can be resolved; otherwise, false.
public bool CanResolve(IRequest request)
{
- Ensure.ArgumentNotNull(request, "request");
+ Contract.Requires(request != null);
return this.Parent.CanResolve(request);
}
@@ -94,7 +83,7 @@ public bool CanResolve(IRequest request)
///
public bool CanResolve(IRequest request, bool ignoreImplicitBindings)
{
- Ensure.ArgumentNotNull(request, "request");
+ Contract.Requires(request != null);
return this.Parent.CanResolve(request, ignoreImplicitBindings);
}
@@ -106,8 +95,8 @@ public bool CanResolve(IRequest request, bool ignoreImplicitBindings)
/// An enumerator of instances that match the request.
public IEnumerable
public class ActivationCache : NinjectComponent, IActivationCache, IPruneable
{
-#if WINDOWS_PHONE || MONO
- ///
- /// The objects that were activated as reference equal weak references.
- ///
- private readonly IDictionary activatedObjects = new Dictionary(new WeakReferenceEqualityComparer());
-
- ///
- /// The objects that were activated as reference equal weak references.
- ///
- private readonly IDictionary deactivatedObjects = new Dictionary(new WeakReferenceEqualityComparer());
-#else
///
/// The objects that were activated as reference equal weak references.
///
@@ -31,7 +42,6 @@ public class ActivationCache : NinjectComponent, IActivationCache, IPruneable
/// The objects that were activated as reference equal weak references.
///
private readonly HashSet deactivatedObjects = new HashSet(new WeakReferenceEqualityComparer());
-#endif
///
/// Initializes a new instance of the class.
@@ -39,10 +49,10 @@ public class ActivationCache : NinjectComponent, IActivationCache, IPruneable
/// The cache pruner.
public ActivationCache(ICachePruner cachePruner)
{
- Ensure.ArgumentNotNull(cachePruner, "cachePruner");
+ Contract.Requires(cachePruner != null);
cachePruner.Start(this);
}
-
+
///
/// Gets the activated object count.
///
@@ -66,7 +76,7 @@ public int DeactivatedObjectCount
return this.deactivatedObjects.Count;
}
}
-
+
///
/// Clears the cache.
///
@@ -89,18 +99,10 @@ public void Clear()
/// The instance to be added.
public void AddActivatedInstance(object instance)
{
-#if PCL
- throw new NotImplementedException();
-#else
lock (this.activatedObjects)
{
-#if WINDOWS_PHONE || MONO || PCL
- this.activatedObjects.Add(new ReferenceEqualWeakReference(instance), true);
-#else
this.activatedObjects.Add(new ReferenceEqualWeakReference(instance));
-#endif
}
-#endif
}
///
@@ -109,18 +111,10 @@ public void AddActivatedInstance(object instance)
/// The instance to be added.
public void AddDeactivatedInstance(object instance)
{
-#if PCL
- throw new NotImplementedException();
-#else
lock (this.deactivatedObjects)
{
-#if WINDOWS_PHONE || MONO || PCL
- this.deactivatedObjects.Add(new ReferenceEqualWeakReference(instance), true);
-#else
this.deactivatedObjects.Add(new ReferenceEqualWeakReference(instance));
-#endif
}
-#endif
}
///
@@ -132,15 +126,7 @@ public void AddDeactivatedInstance(object instance)
///
public bool IsActivated(object instance)
{
-#if PCL
- throw new NotImplementedException();
-#else
-#if WINDOWS_PHONE || MONO || PCL
- return this.activatedObjects.ContainsKey(instance);
-#else
return this.activatedObjects.Contains(instance);
-#endif
-#endif
}
///
@@ -152,15 +138,7 @@ public bool IsActivated(object instance)
///
public bool IsDeactivated(object instance)
{
-#if PCL
- throw new NotImplementedException();
-#else
-#if WINDOWS_PHONE || MONO || PCL
- return this.deactivatedObjects.ContainsKey(instance);
-#else
return this.deactivatedObjects.Contains(instance);
-#endif
-#endif
}
///
@@ -168,9 +146,6 @@ public bool IsDeactivated(object instance)
///
public void Prune()
{
-#if PCL
- throw new NotImplementedException();
-#else
lock (this.activatedObjects)
{
RemoveDeadObjects(this.activatedObjects);
@@ -180,39 +155,15 @@ public void Prune()
{
RemoveDeadObjects(this.deactivatedObjects);
}
-#endif
}
-#if WINDOWS_PHONE || MONO || PCL
- ///
- /// Removes all dead objects.
- ///
- /// The objects collection to be freed of dead objects.
- private static void RemoveDeadObjects(IDictionary objects)
- {
- var deadObjects = objects.Where(entry => !((ReferenceEqualWeakReference)entry.Key).IsAlive).ToList();
- foreach (var deadObject in deadObjects)
- {
- objects.Remove(deadObject.Key);
- }
- }
-#else
///
/// Removes all dead objects.
///
/// The objects collection to be freed of dead objects.
private static void RemoveDeadObjects(HashSet objects)
{
-#if WINRT
- var deadObjects = objects.Where(reference => !((ReferenceEqualWeakReference)reference).IsAlive).ToList();
- foreach (var deadObject in deadObjects)
- {
- objects.Remove(deadObject);
- }
-#else
objects.RemoveWhere(reference => !((ReferenceEqualWeakReference)reference).IsAlive);
-#endif
}
-#endif
}
}
\ No newline at end of file
diff --git a/src/Ninject/Activation/Caching/Cache.cs b/src/Ninject/Activation/Caching/Cache.cs
index d176e1b9..bf7512d6 100644
--- a/src/Ninject/Activation/Caching/Cache.cs
+++ b/src/Ninject/Activation/Caching/Cache.cs
@@ -1,18 +1,31 @@
-#region License
-//
-// Author: Nate Kohari
-// Copyright (c) 2007-2010, Enkari, Ltd.
-//
-// Dual-licensed under the Apache License, Version 2.0, and the Microsoft Public License (Ms-PL).
-// See the file LICENSE.txt for details.
-//
-#endregion
+//-------------------------------------------------------------------------------------------------
+//
+// Copyright (c) 2007-2010, Enkari, Ltd.
+// Copyright (c) 2010-2016, Ninject Project Contributors
+// Authors: Nate Kohari (nate@enkari.com)
+// Remo Gloor (remo.gloor@gmail.com)
+//
+// 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.
+//
+//-------------------------------------------------------------------------------------------------
namespace Ninject.Activation.Caching
{
using System.Collections.Generic;
+ using System.Diagnostics.Contracts;
using System.Linq;
-
using Ninject.Components;
using Ninject.Infrastructure;
using Ninject.Infrastructure.Disposal;
@@ -37,6 +50,9 @@ public class Cache : NinjectComponent, ICache
/// The cache pruner component.
public Cache(IPipeline pipeline, ICachePruner cachePruner)
{
+ Contract.Requires(pipeline != null);
+ Contract.Requires(cachePruner != null);
+
this.Pipeline = pipeline;
cachePruner.Start(this);
}
@@ -57,10 +73,10 @@ public int Count
///
/// Releases resources held by the object.
///
- ///
+ /// True if called manually, otherwise by GC.
public override void Dispose(bool disposing)
{
- if (disposing && !IsDisposed)
+ if (disposing && !this.IsDisposed)
{
this.Clear();
}
@@ -143,7 +159,7 @@ public object TryGet(IContext context)
/// if the instance was found and released; otherwise .
public bool Release(object instance)
{
- lock(this.entries)
+ lock (this.entries)
{
var instanceFound = false;
foreach (var bindingEntry in this.entries.Values.SelectMany(bindingEntries => bindingEntries.Values).ToList())
@@ -208,7 +224,7 @@ public void Clear()
}
///
- /// Gets all entries for a binding withing the selected scope.
+ /// Gets all entries for a binding within the selected scope.
///
/// The bindings.
/// All bindings of a binding.
diff --git a/src/Ninject/Activation/Caching/GarbageCollectionCachePruner.cs b/src/Ninject/Activation/Caching/GarbageCollectionCachePruner.cs
index fadc9cdb..aadee487 100644
--- a/src/Ninject/Activation/Caching/GarbageCollectionCachePruner.cs
+++ b/src/Ninject/Activation/Caching/GarbageCollectionCachePruner.cs
@@ -1,29 +1,35 @@
-#region License
-//
-// Author: Nate Kohari
-// Copyright (c) 2007-2010, Enkari, Ltd.
-//
-// Dual-licensed under the Apache License, Version 2.0, and the Microsoft Public License (Ms-PL).
-// See the file LICENSE.txt for details.
-//
-#endregion
-
-
+//-------------------------------------------------------------------------------------------------
+//
+// Copyright (c) 2007-2010, Enkari, Ltd.
+// Copyright (c) 2010-2016, Ninject Project Contributors
+// Authors: Nate Kohari (nate@enkari.com)
+// Remo Gloor (remo.gloor@gmail.com)
+//
+// 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.
+//
+//-------------------------------------------------------------------------------------------------
namespace Ninject.Activation.Caching
{
using System;
using System.Collections.Generic;
+ using System.Diagnostics.Contracts;
using System.Threading;
using Ninject.Components;
- using Ninject.Infrastructure;
using Ninject.Infrastructure.Language;
-#if WINRT
- using Windows.System.Threading;
-#endif
-
-
///
/// Uses a and some magic to poll
/// the garbage collector to see if it has run.
@@ -34,30 +40,29 @@ public class GarbageCollectionCachePruner : NinjectComponent, ICachePruner
/// indicator for if GC has been run.
///
private readonly WeakReference indicator = new WeakReference(new object());
-
+
///
/// The caches that are being pruned.
///
private readonly List caches = new List();
///
- /// The timer used to trigger the cache pruning
+ /// The timer used to trigger the cache pruning.
///
-#if !WINRT
private Timer timer;
-#else
- private ThreadPoolTimer timer;
-#endif
-#if !PCL
+
+ ///
+ /// The flag to indicate whether the cache pruning is stopped or not.
+ ///
private bool stop;
-#endif
///
/// Releases resources held by the object.
///
+ /// True if called manually, otherwise by GC.
public override void Dispose(bool disposing)
{
- if (disposing && !IsDisposed && this.timer != null)
+ if (disposing && !this.IsDisposed && this.timer != null)
{
this.Stop();
}
@@ -74,13 +79,7 @@ public void Start(IPruneable pruneable)
this.caches.Add(pruneable);
if (this.timer == null)
{
-#if !WINRT
this.timer = new Timer(this.PruneCacheIfGarbageCollectorHasRun, null, this.GetTimeoutInMilliseconds(), Timeout.Infinite);
-#else
-
- this.timer = ThreadPoolTimer.CreatePeriodicTimer(t => this.PruneCacheIfGarbageCollectorHasRun(null),
- TimeSpan.FromMilliseconds(this.GetTimeoutInMilliseconds()));
-#endif
}
}
@@ -89,39 +88,18 @@ public void Start(IPruneable pruneable)
///
public void Stop()
{
-#if PCL
- throw new NotImplementedException();
-#else
lock (this)
{
this.stop = true;
}
- using (var signal = new ManualResetEvent(false))
- {
-#if !WINRT
-#if NETSTANDARD1_3
- this.timer.Dispose();
-#else
- this.timer.Dispose(signal);
-
- signal.WaitOne();
-#endif
-#else
- this.timer.Cancel();
-#endif
-
- this.timer = null;
- this.caches.Clear();
- }
-#endif
+ this.timer.Dispose();
+ this.timer = null;
+ this.caches.Clear();
}
private void PruneCacheIfGarbageCollectorHasRun(object state)
{
-#if PCL
- throw new NotImplementedException();
-#else
lock (this)
{
if (this.stop)
@@ -141,17 +119,14 @@ private void PruneCacheIfGarbageCollectorHasRun(object state)
}
finally
{
-#if !WINRT
this.timer.Change(this.GetTimeoutInMilliseconds(), Timeout.Infinite);
-#endif
}
}
-#endif
}
private int GetTimeoutInMilliseconds()
{
- TimeSpan interval = Settings.CachePruningInterval;
+ var interval = this.Settings.CachePruningInterval;
return interval == TimeSpan.MaxValue ? -1 : (int)interval.TotalMilliseconds;
}
}
diff --git a/src/Ninject/Activation/Caching/IActivationCache.cs b/src/Ninject/Activation/Caching/IActivationCache.cs
index d44c955e..dcc7e496 100644
--- a/src/Ninject/Activation/Caching/IActivationCache.cs
+++ b/src/Ninject/Activation/Caching/IActivationCache.cs
@@ -1,4 +1,27 @@
-namespace Ninject.Activation.Caching
+//-------------------------------------------------------------------------------------------------
+//
+// Copyright (c) 2007-2010, Enkari, Ltd.
+// Copyright (c) 2010-2016, Ninject Project Contributors
+// Authors: Nate Kohari (nate@enkari.com)
+// Remo Gloor (remo.gloor@gmail.com)
+//
+// 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.
+//
+//-------------------------------------------------------------------------------------------------
+
+namespace Ninject.Activation.Caching
{
using Ninject.Components;
@@ -23,7 +46,7 @@ public interface IActivationCache : INinjectComponent
///
/// The instance to be added.
void AddDeactivatedInstance(object instance);
-
+
///
/// Determines whether the specified instance is activated.
///
diff --git a/src/Ninject/Activation/Caching/ICache.cs b/src/Ninject/Activation/Caching/ICache.cs
index 3fc07184..38569e89 100644
--- a/src/Ninject/Activation/Caching/ICache.cs
+++ b/src/Ninject/Activation/Caching/ICache.cs
@@ -1,19 +1,30 @@
-#region License
-//
-// Author: Nate Kohari
-// Copyright (c) 2007-2010, Enkari, Ltd.
-//
-// Dual-licensed under the Apache License, Version 2.0, and the Microsoft Public License (Ms-PL).
-// See the file LICENSE.txt for details.
-//
-#endregion
-#region Using Directives
-using System;
-using Ninject.Components;
-#endregion
+//-------------------------------------------------------------------------------------------------
+//
+// Copyright (c) 2007-2010, Enkari, Ltd.
+// Copyright (c) 2010-2016, Ninject Project Contributors
+// Authors: Nate Kohari (nate@enkari.com)
+// Remo Gloor (remo.gloor@gmail.com)
+//
+// 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.
+//
+//-------------------------------------------------------------------------------------------------
namespace Ninject.Activation.Caching
{
+ using Ninject.Components;
+
///
/// Tracks instances for re-use in certain scopes.
///
diff --git a/src/Ninject/Activation/Caching/ICachePruner.cs b/src/Ninject/Activation/Caching/ICachePruner.cs
index b3a02799..756b363b 100644
--- a/src/Ninject/Activation/Caching/ICachePruner.cs
+++ b/src/Ninject/Activation/Caching/ICachePruner.cs
@@ -1,19 +1,30 @@
-#region License
-//
-// Author: Nate Kohari
-// Copyright (c) 2007-2010, Enkari, Ltd.
-//
-// Dual-licensed under the Apache License, Version 2.0, and the Microsoft Public License (Ms-PL).
-// See the file LICENSE.txt for details.
-//
-#endregion
-#region Using Directives
-using System;
-using Ninject.Components;
-#endregion
+//-------------------------------------------------------------------------------------------------
+//
+// Copyright (c) 2007-2010, Enkari, Ltd.
+// Copyright (c) 2010-2016, Ninject Project Contributors
+// Authors: Nate Kohari (nate@enkari.com)
+// Remo Gloor (remo.gloor@gmail.com)
+//
+// 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.
+//
+//-------------------------------------------------------------------------------------------------
namespace Ninject.Activation.Caching
{
+ using Ninject.Components;
+
///
/// Prunes instances from an based on environmental information.
///
diff --git a/src/Ninject/Activation/Caching/IPruneable.cs b/src/Ninject/Activation/Caching/IPruneable.cs
index 51810480..a52033f0 100644
--- a/src/Ninject/Activation/Caching/IPruneable.cs
+++ b/src/Ninject/Activation/Caching/IPruneable.cs
@@ -1,3 +1,26 @@
+//-------------------------------------------------------------------------------------------------
+//
+// Copyright (c) 2007-2010, Enkari, Ltd.
+// Copyright (c) 2010-2016, Ninject Project Contributors
+// Authors: Nate Kohari (nate@enkari.com)
+// Remo Gloor (remo.gloor@gmail.com)
+//
+// 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.
+//
+//-------------------------------------------------------------------------------------------------
+
namespace Ninject.Activation.Caching
{
///
diff --git a/src/Ninject/Activation/Caching/WeakReferenceEqualityComparer.cs b/src/Ninject/Activation/Caching/WeakReferenceEqualityComparer.cs
index 17916617..b3432d23 100644
--- a/src/Ninject/Activation/Caching/WeakReferenceEqualityComparer.cs
+++ b/src/Ninject/Activation/Caching/WeakReferenceEqualityComparer.cs
@@ -1,8 +1,30 @@
+//-------------------------------------------------------------------------------------------------
+//
+// Copyright (c) 2007-2010, Enkari, Ltd.
+// Copyright (c) 2010-2016, Ninject Project Contributors
+// Authors: Nate Kohari (nate@enkari.com)
+// Remo Gloor (remo.gloor@gmail.com)
+//
+// 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.
+//
+//-------------------------------------------------------------------------------------------------
+
namespace Ninject.Activation.Caching
{
using System.Collections.Generic;
using System.Runtime.CompilerServices;
-
using Ninject.Infrastructure;
///
@@ -11,7 +33,7 @@ namespace Ninject.Activation.Caching
public class WeakReferenceEqualityComparer : IEqualityComparer
{
///
- /// Returns if the specifed objects are equal.
+ /// Returns if the specified objects are equal.
///
/// The first object.
/// The second object.
@@ -29,7 +51,7 @@ public new bool Equals(object x, object y)
public int GetHashCode(object obj)
{
var weakReference = obj as ReferenceEqualWeakReference;
- return weakReference != null ? weakReference.GetHashCode() :
+ return weakReference != null ? weakReference.GetHashCode() :
RuntimeHelpers.GetHashCode(obj);
}
}
diff --git a/src/Ninject/Activation/Context.cs b/src/Ninject/Activation/Context.cs
index 5644ac7b..8b36f72f 100644
--- a/src/Ninject/Activation/Context.cs
+++ b/src/Ninject/Activation/Context.cs
@@ -1,35 +1,37 @@
-//-------------------------------------------------------------------------------
+//-------------------------------------------------------------------------------------------------
//
-// Copyright (c) 2009-2014 Ninject Project Contributors
-//
+// Copyright (c) 2007-2010, Enkari, Ltd.
+// Copyright (c) 2010-2016, Ninject Project Contributors
+// Authors: Nate Kohari (nate@enkari.com)
+// Remo Gloor (remo.gloor@gmail.com)
+//
// 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 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.
//
-//-------------------------------------------------------------------------------
+//-------------------------------------------------------------------------------------------------
namespace Ninject.Activation
{
-using System;
-using System.Collections.Generic;
-using System.Linq;
-using System.Reflection;
-
-using Ninject.Activation.Caching;
-using Ninject.Infrastructure.Introspection;
-using Ninject.Parameters;
-using Ninject.Planning;
-using Ninject.Planning.Bindings;
+ using System;
+ using System.Collections.Generic;
+ using System.Linq;
+ using System.Reflection;
+ using Ninject.Activation.Caching;
+ using Ninject.Infrastructure.Introspection;
+ using Ninject.Parameters;
+ using Ninject.Planning;
+ using Ninject.Planning.Bindings;
///
/// Contains information about the activation of a single instance.
@@ -59,8 +61,8 @@ public Context(IReadOnlyKernel readonlyKernel, IRequest request, IBinding bindin
if (binding.Service.GetTypeInfo().IsGenericTypeDefinition)
{
- HasInferredGenericArguments = true;
- GenericArguments = request.Service.GetTypeInfo().GenericTypeArguments;
+ this.HasInferredGenericArguments = true;
+ this.GenericArguments = request.Service.GetTypeInfo().GenericTypeArguments;
}
}
@@ -85,13 +87,19 @@ public Context(IReadOnlyKernel readonlyKernel, IRequest request, IBinding bindin
///
public bool HasInferredGenericArguments { get; private set; }
- ///
+ ///
+ /// Gets the cache component.
+ ///
public ICache Cache { get; private set; }
- ///
+ ///
+ /// Gets the planner component.
+ ///
public IPlanner Planner { get; private set; }
- ///
+ ///
+ /// Gets the pipeline component.
+ ///
public IPipeline Pipeline { get; private set; }
///
@@ -119,18 +127,18 @@ public object Resolve()
this.cachedScope = this.Request.GetScope() ?? this.Binding.GetScope(this);
if (this.cachedScope != null)
- {
- lock (this.cachedScope)
{
+ lock (this.cachedScope)
+ {
return this.ResolveInternal(this.cachedScope);
+ }
+ }
+ else
+ {
+ return this.ResolveInternal(null);
}
}
- else
- {
- return this.ResolveInternal(null);
- }
- }
- finally
+ finally
{
this.cachedScope = null;
}
diff --git a/src/Ninject/Activation/IContext.cs b/src/Ninject/Activation/IContext.cs
index 4c2ca401..cb73c5b1 100644
--- a/src/Ninject/Activation/IContext.cs
+++ b/src/Ninject/Activation/IContext.cs
@@ -1,24 +1,34 @@
-#region License
-//
-// Author: Nate Kohari
-// Copyright (c) 2007-2010, Enkari, Ltd.
-//
-// Dual-licensed under the Apache License, Version 2.0, and the Microsoft Public License (Ms-PL).
-// See the file LICENSE.txt for details.
-//
-#endregion
-#region Using Directives
-using System;
-using System.Collections.Generic;
-using Ninject.Parameters;
-using Ninject.Planning;
-using Ninject.Planning.Bindings;
-using Ninject.Syntax;
-
-#endregion
+//-------------------------------------------------------------------------------------------------
+//
+// Copyright (c) 2007-2010, Enkari, Ltd.
+// Copyright (c) 2010-2016, Ninject Project Contributors
+// Authors: Nate Kohari (nate@enkari.com)
+// Remo Gloor (remo.gloor@gmail.com)
+//
+// 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.
+//
+//-------------------------------------------------------------------------------------------------
namespace Ninject.Activation
{
+ using System;
+ using System.Collections.Generic;
+ using Ninject.Parameters;
+ using Ninject.Planning;
+ using Ninject.Planning.Bindings;
+
///
/// Contains information about the activation of a single instance.
///
diff --git a/src/Ninject/Activation/IPipeline.cs b/src/Ninject/Activation/IPipeline.cs
index 01a99d1e..3f9f2432 100644
--- a/src/Ninject/Activation/IPipeline.cs
+++ b/src/Ninject/Activation/IPipeline.cs
@@ -1,21 +1,32 @@
-#region License
-//
-// Author: Nate Kohari
-// Copyright (c) 2007-2010, Enkari, Ltd.
-//
-// Dual-licensed under the Apache License, Version 2.0, and the Microsoft Public License (Ms-PL).
-// See the file LICENSE.txt for details.
-//
-#endregion
-#region Using Directives
-using System;
-using System.Collections.Generic;
-using Ninject.Activation.Strategies;
-using Ninject.Components;
-#endregion
+//-------------------------------------------------------------------------------------------------
+//
+// Copyright (c) 2007-2010, Enkari, Ltd.
+// Copyright (c) 2010-2016, Ninject Project Contributors
+// Authors: Nate Kohari (nate@enkari.com)
+// Remo Gloor (remo.gloor@gmail.com)
+//
+// 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.
+//
+//-------------------------------------------------------------------------------------------------
namespace Ninject.Activation
{
+ using System.Collections.Generic;
+ using Ninject.Activation.Strategies;
+ using Ninject.Components;
+
///
/// Drives the activation (injection, etc.) of an instance.
///
diff --git a/src/Ninject/Activation/IProvider.cs b/src/Ninject/Activation/IProvider.cs
index 55a50c7e..164d7d9f 100644
--- a/src/Ninject/Activation/IProvider.cs
+++ b/src/Ninject/Activation/IProvider.cs
@@ -1,18 +1,30 @@
-#region License
-//
-// Author: Nate Kohari
-// Copyright (c) 2007-2010, Enkari, Ltd.
-//
-// Dual-licensed under the Apache License, Version 2.0, and the Microsoft Public License (Ms-PL).
-// See the file LICENSE.txt for details.
-//
-#endregion
-#region Using Directives
-using System;
-#endregion
+//-------------------------------------------------------------------------------------------------
+//
+// Copyright (c) 2007-2010, Enkari, Ltd.
+// Copyright (c) 2010-2016, Ninject Project Contributors
+// Authors: Nate Kohari (nate@enkari.com)
+// Remo Gloor (remo.gloor@gmail.com)
+//
+// 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.
+//
+//-------------------------------------------------------------------------------------------------
namespace Ninject.Activation
{
+ using System;
+
///
/// Creates instances of services.
///
diff --git a/src/Ninject/Activation/IProvider{T}.cs b/src/Ninject/Activation/IProvider{T}.cs
index fff498eb..758cd518 100644
--- a/src/Ninject/Activation/IProvider{T}.cs
+++ b/src/Ninject/Activation/IProvider{T}.cs
@@ -1,8 +1,11 @@
//-------------------------------------------------------------------------------
+//-------------------------------------------------------------------------------------------------
//
-// Copyright (c) 2009-2011 Ninject Project Contributors
-// Authors: Remo Gloor (remo.gloor@gmail.com)
-//
+// Copyright (c) 2007-2010, Enkari, Ltd.
+// Copyright (c) 2010-2016, Ninject Project Contributors
+// Authors: Nate Kohari (nate@enkari.com)
+// Remo Gloor (remo.gloor@gmail.com)
+//
// 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
@@ -26,6 +29,6 @@ namespace Ninject.Activation
///
/// The type provides by this implementation.
public interface IProvider : IProvider
- {
+ {
}
}
\ No newline at end of file
diff --git a/src/Ninject/Activation/IRequest.cs b/src/Ninject/Activation/IRequest.cs
index aa84f9a5..ad467804 100644
--- a/src/Ninject/Activation/IRequest.cs
+++ b/src/Ninject/Activation/IRequest.cs
@@ -1,23 +1,34 @@
-#region License
-//
-// Author: Nate Kohari
-// Copyright (c) 2007-2010, Enkari, Ltd.
-//
-// Dual-licensed under the Apache License, Version 2.0, and the Microsoft Public License (Ms-PL).
-// See the file LICENSE.txt for details.
-//
-#endregion
-#region Using Directives
-using System;
-using System.Collections.Generic;
-using Ninject.Parameters;
-using Ninject.Planning.Bindings;
-using Ninject.Planning.Targets;
-using Ninject.Syntax;
-#endregion
+//-------------------------------------------------------------------------------------------------
+//
+// Copyright (c) 2007-2010, Enkari, Ltd.
+// Copyright (c) 2010-2016, Ninject Project Contributors
+// Authors: Nate Kohari (nate@enkari.com)
+// Remo Gloor (remo.gloor@gmail.com)
+//
+// 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.
+//
+//-------------------------------------------------------------------------------------------------
namespace Ninject.Activation
{
+ using System;
+ using System.Collections.Generic;
+ using Ninject.Parameters;
+ using Ninject.Planning.Bindings;
+ using Ninject.Planning.Targets;
+
///
/// Describes the request for a service resolution.
///
@@ -64,17 +75,17 @@ public interface IRequest
int Depth { get; }
///
- /// Gets or sets value indicating whether the request is optional.
+ /// Gets or sets a value indicating whether the request is optional.
///
bool IsOptional { get; set; }
///
- /// Gets or sets value indicating whether the request should return a unique result.
+ /// Gets or sets a value indicating whether the request should return a unique result.
///
bool IsUnique { get; set; }
///
- /// Gets or sets value indicating whether the request should force to return a unique value even if the request is optional.
+ /// Gets or sets a value indicating whether the request should force to return a unique value even if the request is optional.
/// If this value is set true the request will throw an ActivationException if there are multiple satisfying bindings rather
/// than returning null for the request is optional. For none optional requests this parameter does not change anything.
///
diff --git a/src/Ninject/Activation/InstanceReference.cs b/src/Ninject/Activation/InstanceReference.cs
index 6db3a68f..08973b52 100644
--- a/src/Ninject/Activation/InstanceReference.cs
+++ b/src/Ninject/Activation/InstanceReference.cs
@@ -1,23 +1,31 @@
-#region License
-//
-// Author: Nate Kohari
-// Copyright (c) 2007-2010, Enkari, Ltd.
-//
-// Dual-licensed under the Apache License, Version 2.0, and the Microsoft Public License (Ms-PL).
-// See the file LICENSE.txt for details.
-//
-#endregion
-#region Using Directives
-using System;
-using System.Collections.Generic;
-using System.Security;
-using Ninject.Parameters;
-using Ninject.Planning;
-using Ninject.Planning.Bindings;
-#endregion
+//-------------------------------------------------------------------------------------------------
+//
+// Copyright (c) 2007-2010, Enkari, Ltd.
+// Copyright (c) 2010-2016, Ninject Project Contributors
+// Authors: Nate Kohari (nate@enkari.com)
+// Remo Gloor (remo.gloor@gmail.com)
+//
+// 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.
+//
+//-------------------------------------------------------------------------------------------------
namespace Ninject.Activation
{
+ using System;
+ using System.Security;
+
///
/// Holds an instance during activation or after it has been cached.
///
@@ -33,26 +41,17 @@ public class InstanceReference
///
/// The type in question.
/// if the instance is of the specified type, otherwise .
-
[SecuritySafeCritical]
public bool Is()
{
-#if !SILVERLIGHT && !WINDOWS_PHONE && !MONO && !NETSTANDARD1_3 && !WINRT
- if (System.Runtime.Remoting.RemotingServices.IsTransparentProxy(Instance)
- && System.Runtime.Remoting.RemotingServices.GetRealProxy(Instance).GetType().Name == "RemotingProxy")
+#if !CORE
+ if (System.Runtime.Remoting.RemotingServices.IsTransparentProxy(this.Instance)
+ && System.Runtime.Remoting.RemotingServices.GetRealProxy(this.Instance).GetType().Name == "RemotingProxy")
{
-// ReSharper disable UseIsOperator.1
-// ReSharper disable PossibleMistakenCallToGetType.1
-// ReSharper disable UseMethodIsInstanceOfType
-// Must call typeof(T).IsAssignableFrom(Instance.GetType()) to convert the TransparentProxy to the actual proxy type
- return typeof(T).IsAssignableFrom(Instance.GetType());
-// ReSharper restore UseMethodIsInstanceOfType
-// ReSharper restore PossibleMistakenCallToGetType.1
-// ReSharper restore UseIsOperator.1
- };
+ return typeof(T).IsAssignableFrom(this.Instance.GetType());
+ }
#endif
-
- return Instance is T;
+ return this.Instance is T;
}
///
@@ -62,7 +61,7 @@ public bool Is()
/// The instance.
public T As()
{
- return (T)Instance;
+ return (T)this.Instance;
}
///
@@ -73,7 +72,9 @@ public T As()
public void IfInstanceIs(Action action)
{
if (this.Is())
- action((T)Instance);
+ {
+ action((T)this.Instance);
+ }
}
}
}
\ No newline at end of file
diff --git a/src/Ninject/Activation/Pipeline.cs b/src/Ninject/Activation/Pipeline.cs
index 6974a941..c64b3efc 100644
--- a/src/Ninject/Activation/Pipeline.cs
+++ b/src/Ninject/Activation/Pipeline.cs
@@ -1,16 +1,30 @@
-#region License
-//
-// Author: Nate Kohari
-// Copyright (c) 2007-2010, Enkari, Ltd.
-//
-// Dual-licensed under the Apache License, Version 2.0, and the Microsoft Public License (Ms-PL).
-// See the file LICENSE.txt for details.
-//
-#endregion
+//-------------------------------------------------------------------------------------------------
+//
+// Copyright (c) 2007-2010, Enkari, Ltd.
+// Copyright (c) 2010-2016, Ninject Project Contributors
+// Authors: Nate Kohari (nate@enkari.com)
+// Remo Gloor (remo.gloor@gmail.com)
+//
+// 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.
+//
+//-------------------------------------------------------------------------------------------------
namespace Ninject.Activation
{
using System.Collections.Generic;
+ using System.Diagnostics.Contracts;
using System.Linq;
using Ninject.Activation.Caching;
using Ninject.Activation.Strategies;
@@ -35,8 +49,8 @@ public class Pipeline : NinjectComponent, IPipeline
/// The activation cache.
public Pipeline(IEnumerable strategies, IActivationCache activationCache)
{
- Ensure.ArgumentNotNull(strategies, "strategies");
- Ensure.ArgumentNotNull(activationCache, "activationCache");
+ Contract.Requires(strategies != null);
+ Contract.Requires(activationCache != null);
this.Strategies = strategies.ToList();
this.activationCache = activationCache;
@@ -54,8 +68,8 @@ public Pipeline(IEnumerable strategies, IActivationCache ac
/// The instance reference.
public void Activate(IContext context, InstanceReference reference)
{
- Ensure.ArgumentNotNull(context, "context");
- Ensure.ArgumentNotNull(reference, "reference");
+ Contract.Requires(context != null);
+ Contract.Requires(reference != null);
if (!this.activationCache.IsActivated(reference.Instance))
{
@@ -70,8 +84,8 @@ public void Activate(IContext context, InstanceReference reference)
/// The instance reference.
public void Deactivate(IContext context, InstanceReference reference)
{
- Ensure.ArgumentNotNull(context, "context");
- Ensure.ArgumentNotNull(reference, "reference");
+ Contract.Requires(context != null);
+ Contract.Requires(reference != null);
if (!this.activationCache.IsDeactivated(reference.Instance))
{
diff --git a/src/Ninject/Activation/Provider.cs b/src/Ninject/Activation/Provider.cs
index df66be1c..2a0abea8 100644
--- a/src/Ninject/Activation/Provider.cs
+++ b/src/Ninject/Activation/Provider.cs
@@ -1,12 +1,25 @@
-#region License
-//
-// Author: Nate Kohari
-// Copyright (c) 2007-2010, Enkari, Ltd.
-//
-// Dual-licensed under the Apache License, Version 2.0, and the Microsoft Public License (Ms-PL).
-// See the file LICENSE.txt for details.
-//
-#endregion
+//-------------------------------------------------------------------------------------------------
+//
+// Copyright (c) 2007-2010, Enkari, Ltd.
+// Copyright (c) 2010-2016, Ninject Project Contributors
+// Authors: Nate Kohari (nate@enkari.com)
+// Remo Gloor (remo.gloor@gmail.com)
+//
+// 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.
+//
+//-------------------------------------------------------------------------------------------------
namespace Ninject.Activation
{
diff --git a/src/Ninject/Activation/Providers/CallbackProvider.cs b/src/Ninject/Activation/Providers/CallbackProvider.cs
index 65cb4b11..1127022e 100644
--- a/src/Ninject/Activation/Providers/CallbackProvider.cs
+++ b/src/Ninject/Activation/Providers/CallbackProvider.cs
@@ -1,19 +1,31 @@
-#region License
-//
-// Author: Nate Kohari
-// Copyright (c) 2007-2010, Enkari, Ltd.
-//
-// Dual-licensed under the Apache License, Version 2.0, and the Microsoft Public License (Ms-PL).
-// See the file LICENSE.txt for details.
-//
-#endregion
-#region Using Directives
-using System;
-using Ninject.Infrastructure;
-#endregion
+//-------------------------------------------------------------------------------------------------
+//
+// Copyright (c) 2007-2010, Enkari, Ltd.
+// Copyright (c) 2010-2016, Ninject Project Contributors
+// Authors: Nate Kohari (nate@enkari.com)
+// Remo Gloor (remo.gloor@gmail.com)
+//
+// 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.
+//
+//-------------------------------------------------------------------------------------------------
namespace Ninject.Activation.Providers
{
+ using System;
+ using System.Diagnostics.Contracts;
+
///
/// A provider that delegates to a callback method to create instances.
///
@@ -21,27 +33,25 @@ namespace Ninject.Activation.Providers
public class CallbackProvider : Provider
{
///
- /// Gets the callback method used by the provider.
- ///
- public Func Method { get; private set; }
-
- ///
- /// Initializes a new instance of the CallbackProvider<T> class.
+ /// Initializes a new instance of the class.
///
/// The callback method that will be called to create instances.
public CallbackProvider(Func method)
{
- Method = method;
+ Contract.Requires(method != null);
+ this.Method = method;
}
+ ///
+ /// Gets the callback method used by the provider.
+ ///
+ public Func Method { get; private set; }
+
///
/// Invokes the callback method to create an instance.
///
/// The context.
/// The created instance.
- protected override T CreateInstance(IContext context)
- {
- return Method(context);
- }
+ protected override T CreateInstance(IContext context) => this.Method(context);
}
}
\ No newline at end of file
diff --git a/src/Ninject/Activation/Providers/ConstantProvider.cs b/src/Ninject/Activation/Providers/ConstantProvider.cs
index 7a918080..d795716d 100644
--- a/src/Ninject/Activation/Providers/ConstantProvider.cs
+++ b/src/Ninject/Activation/Providers/ConstantProvider.cs
@@ -1,16 +1,25 @@
-#region License
-//
-// Author: Nate Kohari
-// Copyright (c) 2007-2010, Enkari, Ltd.
-//
-// Dual-licensed under the Apache License, Version 2.0, and the Microsoft Public License (Ms-PL).
-// See the file LICENSE.txt for details.
-//
-#endregion
-#region Using Directives
-using System;
-using Ninject.Infrastructure;
-#endregion
+//-------------------------------------------------------------------------------------------------
+//
+// Copyright (c) 2007-2010, Enkari, Ltd.
+// Copyright (c) 2010-2016, Ninject Project Contributors
+// Authors: Nate Kohari (nate@enkari.com)
+// Remo Gloor (remo.gloor@gmail.com)
+//
+// 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.
+//
+//-------------------------------------------------------------------------------------------------
namespace Ninject.Activation.Providers
{
@@ -21,19 +30,19 @@ namespace Ninject.Activation.Providers
public class ConstantProvider : Provider
{
///
- /// Gets the value that the provider will return.
- ///
- public T Value { get; private set; }
-
- ///
- /// Initializes a new instance of the ConstantProvider<T> class.
+ /// Initializes a new instance of the class.
///
/// The value that the provider should return.
public ConstantProvider(T value)
{
- Value = value;
+ this.Value = value;
}
+ ///
+ /// Gets the value that the provider will return.
+ ///
+ public T Value { get; private set; }
+
///
/// Creates an instance within the specified context.
///
@@ -41,7 +50,7 @@ public ConstantProvider(T value)
/// The constant value this provider returns.
protected override T CreateInstance(IContext context)
{
- return Value;
+ return this.Value;
}
}
}
\ No newline at end of file
diff --git a/src/Ninject/Activation/Providers/StandardProvider.cs b/src/Ninject/Activation/Providers/StandardProvider.cs
index 85bea304..55d04963 100644
--- a/src/Ninject/Activation/Providers/StandardProvider.cs
+++ b/src/Ninject/Activation/Providers/StandardProvider.cs
@@ -1,15 +1,19 @@
//-------------------------------------------------------------------------------
+//-------------------------------------------------------------------------------------------------
//
-// Copyright (c) 2009-2014 Ninject Project Contributors
-//
+// Copyright (c) 2007-2010, Enkari, Ltd.
+// Copyright (c) 2010-2016, Ninject Project Contributors
+// Authors: Nate Kohari (nate@enkari.com)
+// Remo Gloor (remo.gloor@gmail.com)
+//
// 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 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.
@@ -20,16 +24,17 @@
namespace Ninject.Activation.Providers
{
-using System;
-using System.Linq;
+ using System;
+ using System.Diagnostics.Contracts;
+ using System.Linq;
using System.Reflection;
-using Ninject.Infrastructure.Introspection;
+ using Ninject.Infrastructure.Introspection;
using Ninject.Infrastructure.Language;
-using Ninject.Parameters;
+ using Ninject.Parameters;
using Ninject.Planning.Bindings;
-using Ninject.Planning.Directives;
-using Ninject.Planning.Targets;
-using Ninject.Selection;
+ using Ninject.Planning.Directives;
+ using Ninject.Planning.Targets;
+ using Ninject.Selection;
using Ninject.Selection.Heuristics;
///
@@ -44,6 +49,9 @@ public class StandardProvider : IProvider
/// The constructor scorer component.
public StandardProvider(Type type, IConstructorScorer constructorScorer)
{
+ Contract.Requires(type != null);
+ Contract.Requires(constructorScorer != null);
+
this.Type = type;
this.ConstructorScorer = constructorScorer;
}
@@ -58,62 +66,13 @@ public StandardProvider(Type type, IConstructorScorer constructorScorer)
///
public IConstructorScorer ConstructorScorer { get; private set; }
- ///
- /// Creates an instance within the specified context.
- ///
- /// The context.
- /// The created instance.
- public virtual object Create(IContext context)
- {
- context.BuildPlan(this.GetImplementationType(context.Request.Service));
-
- var directive = this.DetermineConstructorInjectionDirective(context);
-
- var arguments = directive.Targets.Select(target => this.GetValue(context, target)).ToArray();
-
- return directive.Injector(arguments);
- }
-
- ///
- /// Gets the value to inject into the specified target.
- ///
- /// The context.
- /// The target.
- /// The value to inject into the specified target.
- public object GetValue(IContext context, ITarget target)
- {
- var parameter = context
- .Parameters.OfType()
- .SingleOrDefault(p => p.AppliesToTarget(context, target));
- return parameter != null ? parameter.GetValue(context, target) : target.ResolveWithin(context);
- }
-
- ///
- /// Gets the implementation type that the provider will activate an instance of
- /// for the specified service.
- ///
- /// The service in question.
- /// The implementation type that will be activated.
- public Type GetImplementationType(Type service)
- {
- return Type.GetTypeInfo().ContainsGenericParameters ?
- Type.MakeGenericType(service.GetTypeInfo().GenericTypeArguments) :
- Type;
- }
-
///
/// Gets a callback that creates an instance of the
/// for the specified type.
///
- ///
- /// The prototype the provider instance will create.
- ///
- ///
- /// The selector.
- ///
- ///
- /// The created callback.
- ///
+ /// The prototype the provider instance will create.
+ /// The selector.
+ /// The created callback.
public static Func GetCreationCallback(Type prototype, ISelector selector)
{
var provider = new StandardProvider(prototype, selector.ConstructorScorer);
@@ -150,6 +109,49 @@ public static void AssignProviderCallback(IBindingConfiguration bindingConfigura
selector => provider.ConstructorScorer = selector.ConstructorScorer;
}
+ ///
+ /// Creates an instance within the specified context.
+ ///
+ /// The context.
+ /// The created instance.
+ public virtual object Create(IContext context)
+ {
+ context.BuildPlan(this.GetImplementationType(context.Request.Service));
+
+ var directive = this.DetermineConstructorInjectionDirective(context);
+
+ var arguments = directive.Targets.Select(target => this.GetValue(context, target)).ToArray();
+
+ return directive.Injector(arguments);
+ }
+
+ ///
+ /// Gets the value to inject into the specified target.
+ ///
+ /// The context.
+ /// The target.
+ /// The value to inject into the specified target.
+ public object GetValue(IContext context, ITarget target)
+ {
+ var parameter = context
+ .Parameters.OfType()
+ .SingleOrDefault(p => p.AppliesToTarget(context, target));
+ return parameter != null ? parameter.GetValue(context, target) : target.ResolveWithin(context);
+ }
+
+ ///
+ /// Gets the implementation type that the provider will activate an instance of
+ /// for the specified service.
+ ///
+ /// The service in question.
+ /// The implementation type that will be activated.
+ public Type GetImplementationType(Type service)
+ {
+ return this.Type.GetTypeInfo().ContainsGenericParameters ?
+ this.Type.MakeGenericType(service.GetTypeInfo().GenericTypeArguments) :
+ this.Type;
+ }
+
private ConstructorInjectionDirective DetermineConstructorInjectionDirective(IContext context)
{
var directives = context.Plan.ConstructorInjectionDirectives;
@@ -157,7 +159,8 @@ private ConstructorInjectionDirective DetermineConstructorInjectionDirective(ICo
{
return directives[0];
}
- IGrouping bestDirectives =
+
+ var bestDirectives =
directives
.GroupBy(option => this.ConstructorScorer.Score(context, option))
.OrderByDescending(g => g.Key)
diff --git a/src/Ninject/Activation/Request.cs b/src/Ninject/Activation/Request.cs
index e0db702b..6107729a 100644
--- a/src/Ninject/Activation/Request.cs
+++ b/src/Ninject/Activation/Request.cs
@@ -1,30 +1,83 @@
-#region License
-//
-// Author: Nate Kohari
-// Copyright (c) 2007-2010, Enkari, Ltd.
-//
-// Dual-licensed under the Apache License, Version 2.0, and the Microsoft Public License (Ms-PL).
-// See the file LICENSE.txt for details.
-//
-#endregion
-#region Using Directives
-using System;
-using System.Collections.Generic;
-using System.Linq;
-using Ninject.Infrastructure;
-using Ninject.Infrastructure.Introspection;
-using Ninject.Parameters;
-using Ninject.Planning.Bindings;
-using Ninject.Planning.Targets;
-#endregion
+//-------------------------------------------------------------------------------------------------
+//
+// Copyright (c) 2007-2010, Enkari, Ltd.
+// Copyright (c) 2010-2016, Ninject Project Contributors
+// Authors: Nate Kohari (nate@enkari.com)
+// Remo Gloor (remo.gloor@gmail.com)
+//
+// 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.
+//
+//-------------------------------------------------------------------------------------------------
namespace Ninject.Activation
{
+ using System;
+ using System.Collections.Generic;
+ using System.Linq;
+ using Ninject.Infrastructure.Introspection;
+ using Ninject.Parameters;
+ using Ninject.Planning.Bindings;
+ using Ninject.Planning.Targets;
+
///
/// Describes the request for a service resolution.
///
public class Request : IRequest
{
+ ///
+ /// Initializes a new instance of the class.
+ ///
+ /// The service that was requested.
+ /// The constraint that will be applied to filter the bindings used for the request.
+ /// The parameters that affect the resolution.
+ /// The scope callback, if an external scope was specified.
+ /// True if the request is optional; otherwise, false.
+ /// True if the request should return a unique result; otherwise, false.
+ public Request(Type service, Func constraint, IEnumerable parameters, Func scopeCallback, bool isOptional, bool isUnique)
+ {
+ this.Service = service;
+ this.Constraint = constraint;
+ this.Parameters = parameters.ToList();
+ this.ScopeCallback = scopeCallback;
+ this.ActiveBindings = new Stack();
+ this.Depth = 0;
+ this.IsOptional = isOptional;
+ this.IsUnique = isUnique;
+ }
+
+ ///
+ /// Initializes a new instance of the class.
+ ///
+ /// The parent context.
+ /// The service that was requested.
+ /// The target that will receive the injection.
+ /// The scope callback, if an external scope was specified.
+ public Request(IContext parentContext, Type service, ITarget target, Func scopeCallback)
+ {
+ this.ParentContext = parentContext;
+ this.ParentRequest = parentContext.Request;
+ this.Service = service;
+ this.Target = target;
+ this.Constraint = target.Constraint;
+ this.IsOptional = target.IsOptional;
+ this.Parameters = parentContext.Parameters.Where(p => p.ShouldInherit).ToList();
+ this.ScopeCallback = scopeCallback;
+ this.ActiveBindings = new Stack(this.ParentRequest.ActiveBindings);
+ this.Depth = this.ParentRequest.Depth + 1;
+ }
+
///
/// Gets the service that was requested.
///
@@ -66,12 +119,12 @@ public class Request : IRequest
public int Depth { get; private set; }
///
- /// Gets or sets value indicating whether the request is optional.
+ /// Gets or sets a value indicating whether the request is optional.
///
public bool IsOptional { get; set; }
///
- /// Gets or sets value indicating whether the request is for a single service.
+ /// Gets or sets a value indicating whether the request is for a single service.
///
public bool IsUnique
{
@@ -79,7 +132,7 @@ public bool IsUnique
}
///
- /// Gets or sets value indicating whether the request should force to return a unique value even if the request is optional.
+ /// Gets or sets a value indicating whether the request should force to return a unique value even if the request is optional.
/// If this value is set true the request will throw an ActivationException if there are multiple satisfying bindings rather
/// than returning null for the request is optional. For none optional requests this parameter does not change anything.
///
@@ -87,54 +140,12 @@ public bool ForceUnique
{
get; set;
}
-
+
///
/// Gets the callback that resolves the scope for the request, if an external scope was provided.
///
public Func ScopeCallback { get; private set; }
- ///
- /// Initializes a new instance of the class.
- ///
- /// The service that was requested.
- /// The constraint that will be applied to filter the bindings used for the request.
- /// The parameters that affect the resolution.
- /// The scope callback, if an external scope was specified.
- /// True if the request is optional; otherwise, false.
- /// True if the request should return a unique result; otherwise, false.
- public Request(Type service, Func constraint, IEnumerable parameters, Func scopeCallback, bool isOptional, bool isUnique)
- {
- this.Service = service;
- this.Constraint = constraint;
- this.Parameters = parameters.ToList();
- this.ScopeCallback = scopeCallback;
- this.ActiveBindings = new Stack();
- this.Depth = 0;
- this.IsOptional = isOptional;
- this.IsUnique = isUnique;
- }
-
- ///
- /// Initializes a new instance of the class.
- ///
- /// The parent context.
- /// The service that was requested.
- /// The target that will receive the injection.
- /// The scope callback, if an external scope was specified.
- public Request(IContext parentContext, Type service, ITarget target, Func scopeCallback)
- {
- this.ParentContext = parentContext;
- this.ParentRequest = parentContext.Request;
- this.Service = service;
- this.Target = target;
- this.Constraint = target.Constraint;
- this.IsOptional = target.IsOptional;
- this.Parameters = parentContext.Parameters.Where(p => p.ShouldInherit).ToList();
- this.ScopeCallback = scopeCallback;
- this.ActiveBindings = new Stack(ParentRequest.ActiveBindings);
- this.Depth = ParentRequest.Depth + 1;
- }
-
///
/// Determines whether the specified binding satisfies the constraints defined on this request.
///
@@ -142,7 +153,7 @@ public Request(IContext parentContext, Type service, ITarget target, FuncTrue if the binding satisfies the constraints; otherwise false.
public bool Matches(IBinding binding)
{
- return Constraint == null || Constraint(binding.Metadata);
+ return this.Constraint == null || this.Constraint(binding.Metadata);
}
///
@@ -151,7 +162,7 @@ public bool Matches(IBinding binding)
/// The object that acts as the scope.
public object GetScope()
{
- return ScopeCallback == null ? null : ScopeCallback();
+ return this.ScopeCallback == null ? null : this.ScopeCallback();
}
///
@@ -163,7 +174,7 @@ public object GetScope()
/// The child request.
public IRequest CreateChild(Type service, IContext parentContext, ITarget target)
{
- return new Request(parentContext, service, target, ScopeCallback);
+ return new Request(parentContext, service, target, this.ScopeCallback);
}
///
diff --git a/src/Ninject/Activation/Strategies/ActivationCacheStrategy.cs b/src/Ninject/Activation/Strategies/ActivationCacheStrategy.cs
index cc7de1a7..7f46b4dc 100644
--- a/src/Ninject/Activation/Strategies/ActivationCacheStrategy.cs
+++ b/src/Ninject/Activation/Strategies/ActivationCacheStrategy.cs
@@ -1,5 +1,29 @@
+//-------------------------------------------------------------------------------------------------
+//
+// Copyright (c) 2007-2010, Enkari, Ltd.
+// Copyright (c) 2010-2016, Ninject Project Contributors
+// Authors: Nate Kohari (nate@enkari.com)
+// Remo Gloor (remo.gloor@gmail.com)
+//
+// 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.
+//
+//-------------------------------------------------------------------------------------------------
+
namespace Ninject.Activation.Strategies
{
+ using System.Diagnostics.Contracts;
using Ninject.Activation.Caching;
using Ninject.Infrastructure;
@@ -19,7 +43,7 @@ public class ActivationCacheStrategy : IActivationStrategy
/// The activation cache.
public ActivationCacheStrategy(IActivationCache activationCache)
{
- Ensure.ArgumentNotNull(activationCache, "activationCache");
+ Contract.Requires(activationCache != null);
this.activationCache = activationCache;
}
@@ -28,7 +52,7 @@ public ActivationCacheStrategy(IActivationCache activationCache)
///
/// The ninject settings.
public INinjectSettings Settings { get; set; }
-
+
///
/// Performs application-defined tasks associated with freeing, releasing, or resetting unmanaged resources.
///
diff --git a/src/Ninject/Activation/Strategies/ActivationStrategy.cs b/src/Ninject/Activation/Strategies/ActivationStrategy.cs
index b331c60b..026ea507 100644
--- a/src/Ninject/Activation/Strategies/ActivationStrategy.cs
+++ b/src/Ninject/Activation/Strategies/ActivationStrategy.cs
@@ -1,19 +1,30 @@
-#region License
-//
-// Author: Nate Kohari
-// Copyright (c) 2007-2010, Enkari, Ltd.
-//
-// Dual-licensed under the Apache License, Version 2.0, and the Microsoft Public License (Ms-PL).
-// See the file LICENSE.txt for details.
-//
-#endregion
-#region Using Directives
-using System;
-using Ninject.Components;
-#endregion
+//-------------------------------------------------------------------------------------------------
+//
+// Copyright (c) 2007-2010, Enkari, Ltd.
+// Copyright (c) 2010-2016, Ninject Project Contributors
+// Authors: Nate Kohari (nate@enkari.com)
+// Remo Gloor (remo.gloor@gmail.com)
+//
+// 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.
+//
+//-------------------------------------------------------------------------------------------------
namespace Ninject.Activation.Strategies
{
+ using Ninject.Components;
+
///
/// Contributes to a , and is called during the activation
/// and deactivation of an instance.
@@ -25,13 +36,17 @@ public abstract class ActivationStrategy : NinjectComponent, IActivationStrategy
///
/// The context.
/// A reference to the instance being activated.
- public virtual void Activate(IContext context, InstanceReference reference) { }
+ public virtual void Activate(IContext context, InstanceReference reference)
+ {
+ }
///
/// Contributes to the deactivation of the instance in the specified context.
///
/// The context.
/// A reference to the instance being deactivated.
- public virtual void Deactivate(IContext context, InstanceReference reference) { }
+ public virtual void Deactivate(IContext context, InstanceReference reference)
+ {
+ }
}
}
\ No newline at end of file
diff --git a/src/Ninject/Activation/Strategies/BindingActionStrategy.cs b/src/Ninject/Activation/Strategies/BindingActionStrategy.cs
index dba6999d..865dfbc8 100644
--- a/src/Ninject/Activation/Strategies/BindingActionStrategy.cs
+++ b/src/Ninject/Activation/Strategies/BindingActionStrategy.cs
@@ -1,20 +1,30 @@
-#region License
-//
-// Author: Nate Kohari
-// Copyright (c) 2007-2010, Enkari, Ltd.
-//
-// Dual-licensed under the Apache License, Version 2.0, and the Microsoft Public License (Ms-PL).
-// See the file LICENSE.txt for details.
-//
-#endregion
-#region Using Directives
-using System;
-using Ninject.Infrastructure;
-using Ninject.Infrastructure.Language;
-#endregion
+//-------------------------------------------------------------------------------------------------
+//
+// Copyright (c) 2007-2010, Enkari, Ltd.
+// Copyright (c) 2010-2016, Ninject Project Contributors
+// Authors: Nate Kohari (nate@enkari.com)
+// Remo Gloor (remo.gloor@gmail.com)
+//
+// 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.
+//
+//-------------------------------------------------------------------------------------------------
namespace Ninject.Activation.Strategies
{
+ using Ninject.Infrastructure.Language;
+
///
/// Executes actions defined on the binding during activation and deactivation.
///
diff --git a/src/Ninject/Activation/Strategies/DisposableStrategy.cs b/src/Ninject/Activation/Strategies/DisposableStrategy.cs
index 36f9291c..8d69b919 100644
--- a/src/Ninject/Activation/Strategies/DisposableStrategy.cs
+++ b/src/Ninject/Activation/Strategies/DisposableStrategy.cs
@@ -1,18 +1,30 @@
-#region License
-//
-// Author: Nate Kohari
-// Copyright (c) 2007-2010, Enkari, Ltd.
-//
-// Dual-licensed under the Apache License, Version 2.0, and the Microsoft Public License (Ms-PL).
-// See the file LICENSE.txt for details.
-//
-#endregion
-#region Using Directives
-using System;
-#endregion
+//-------------------------------------------------------------------------------------------------
+//
+// Copyright (c) 2007-2010, Enkari, Ltd.
+// Copyright (c) 2010-2016, Ninject Project Contributors
+// Authors: Nate Kohari (nate@enkari.com)
+// Remo Gloor (remo.gloor@gmail.com)
+//
+// 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.
+//
+//-------------------------------------------------------------------------------------------------
namespace Ninject.Activation.Strategies
{
+ using System;
+
///
/// During deactivation, disposes instances that implement .
///
diff --git a/src/Ninject/Activation/Strategies/IActivationStrategy.cs b/src/Ninject/Activation/Strategies/IActivationStrategy.cs
index 2d53666c..efab4d31 100644
--- a/src/Ninject/Activation/Strategies/IActivationStrategy.cs
+++ b/src/Ninject/Activation/Strategies/IActivationStrategy.cs
@@ -1,19 +1,30 @@
-#region License
-//
-// Author: Nate Kohari
-// Copyright (c) 2007-2010, Enkari, Ltd.
-//
-// Dual-licensed under the Apache License, Version 2.0, and the Microsoft Public License (Ms-PL).
-// See the file LICENSE.txt for details.
-//
-#endregion
-#region Using Directives
-using System;
-using Ninject.Components;
-#endregion
+//-------------------------------------------------------------------------------------------------
+//
+// Copyright (c) 2007-2010, Enkari, Ltd.
+// Copyright (c) 2010-2016, Ninject Project Contributors
+// Authors: Nate Kohari (nate@enkari.com)
+// Remo Gloor (remo.gloor@gmail.com)
+//
+// 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.
+//
+//-------------------------------------------------------------------------------------------------
namespace Ninject.Activation.Strategies
{
+ using Ninject.Components;
+
///
/// Contributes to a , and is called during the activation
/// and deactivation of an instance.
diff --git a/src/Ninject/Activation/Strategies/InitializableStrategy.cs b/src/Ninject/Activation/Strategies/InitializableStrategy.cs
index 5d5be78d..a2608385 100644
--- a/src/Ninject/Activation/Strategies/InitializableStrategy.cs
+++ b/src/Ninject/Activation/Strategies/InitializableStrategy.cs
@@ -1,15 +1,25 @@
-#region License
-//
-// Author: Nate Kohari
-// Copyright (c) 2007-2010, Enkari, Ltd.
-//
-// Dual-licensed under the Apache License, Version 2.0, and the Microsoft Public License (Ms-PL).
-// See the file LICENSE.txt for details.
-//
-#endregion
-#region Using Directives
-using System;
-#endregion
+//-------------------------------------------------------------------------------------------------
+//
+// Copyright (c) 2007-2010, Enkari, Ltd.
+// Copyright (c) 2010-2016, Ninject Project Contributors
+// Authors: Nate Kohari (nate@enkari.com)
+// Remo Gloor (remo.gloor@gmail.com)
+//
+// 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.
+//
+//-------------------------------------------------------------------------------------------------
namespace Ninject.Activation.Strategies
{
diff --git a/src/Ninject/Activation/Strategies/MethodInjectionStrategy.cs b/src/Ninject/Activation/Strategies/MethodInjectionStrategy.cs
index 1629982e..762e59e4 100644
--- a/src/Ninject/Activation/Strategies/MethodInjectionStrategy.cs
+++ b/src/Ninject/Activation/Strategies/MethodInjectionStrategy.cs
@@ -1,22 +1,31 @@
-#region License
-//
-// Author: Nate Kohari
-// Copyright (c) 2007-2010, Enkari, Ltd.
-//
-// Dual-licensed under the Apache License, Version 2.0, and the Microsoft Public License (Ms-PL).
-// See the file LICENSE.txt for details.
-//
-#endregion
-#region Using Directives
-using System;
-using System.Linq;
-using Ninject.Infrastructure;
-using Ninject.Injection;
-using Ninject.Planning.Directives;
-#endregion
+//-------------------------------------------------------------------------------------------------
+//
+// Copyright (c) 2007-2010, Enkari, Ltd.
+// Copyright (c) 2010-2016, Ninject Project Contributors
+// Authors: Nate Kohari (nate@enkari.com)
+// Remo Gloor (remo.gloor@gmail.com)
+//
+// 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.
+//
+//-------------------------------------------------------------------------------------------------
namespace Ninject.Activation.Strategies
{
+ using System.Linq;
+ using Ninject.Planning.Directives;
+
///
/// Injects methods on an instance during activation.
///
diff --git a/src/Ninject/Activation/Strategies/PropertyInjectionStrategy.cs b/src/Ninject/Activation/Strategies/PropertyInjectionStrategy.cs
index 94bcf8ef..8b3b8abe 100644
--- a/src/Ninject/Activation/Strategies/PropertyInjectionStrategy.cs
+++ b/src/Ninject/Activation/Strategies/PropertyInjectionStrategy.cs
@@ -1,37 +1,44 @@
-#region License
-//
-// Author: Nate Kohari
-// Copyright (c) 2007-2010, Enkari, Ltd.
-//
-// Dual-licensed under the Apache License, Version 2.0, and the Microsoft Public License (Ms-PL).
-// See the file LICENSE.txt for details.
-//
-#endregion
-#region Using Directives
-using System;
-using System.Collections.Generic;
-using System.Linq;
-using System.Reflection;
-using Ninject.Infrastructure;
-using Ninject.Infrastructure.Introspection;
-using Ninject.Infrastructure.Language;
-using Ninject.Injection;
-using Ninject.Parameters;
-using Ninject.Planning.Directives;
-using Ninject.Planning.Targets;
-#endregion
+//-------------------------------------------------------------------------------------------------
+//
+// Copyright (c) 2007-2010, Enkari, Ltd.
+// Copyright (c) 2010-2016, Ninject Project Contributors
+// Authors: Nate Kohari (nate@enkari.com)
+// Remo Gloor (remo.gloor@gmail.com)
+//
+// 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.
+//
+//-------------------------------------------------------------------------------------------------
namespace Ninject.Activation.Strategies
{
+ using System;
+ using System.Collections.Generic;
+ using System.Linq;
+ using System.Reflection;
+ using Ninject.Infrastructure.Introspection;
+ using Ninject.Injection;
+ using Ninject.Parameters;
+ using Ninject.Planning.Directives;
+ using Ninject.Planning.Targets;
+
///
/// Injects properties on an instance during activation.
///
public class PropertyInjectionStrategy : ActivationStrategy
{
- ///
- /// Gets the injector factory component.
- ///
- public IInjectorFactory InjectorFactory { get; set; }
+ private const BindingFlags DefaultFlags = BindingFlags.Public | BindingFlags.Instance;
///
/// Initializes a new instance of the class.
@@ -42,6 +49,23 @@ public PropertyInjectionStrategy(IInjectorFactory injectorFactory)
this.InjectorFactory = injectorFactory;
}
+ ///
+ /// Gets the injector factory component.
+ ///
+ public IInjectorFactory InjectorFactory { get; private set; }
+
+ private BindingFlags Flags
+ {
+ get
+ {
+#if !NO_LCG
+ return this.Settings.InjectNonPublic ? (DefaultFlags | BindingFlags.NonPublic) : DefaultFlags;
+#else
+ return DefaultFlags;
+#endif
+ }
+ }
+
///
/// Injects values into the properties as described by s
/// contained in the plan.
@@ -54,15 +78,13 @@ public override void Activate(IContext context, InstanceReference reference)
foreach (var directive in context.Plan.GetAll())
{
- object value = this.GetValue(context, directive.Target, propertyValues);
+ var value = this.GetValue(context, directive.Target, propertyValues);
directive.Injector(reference.Instance, value);
}
this.AssignPropertyOverrides(context, reference, propertyValues);
}
-
-
///
/// Applies user supplied override values to instance properties.
///
@@ -71,11 +93,11 @@ public override void Activate(IContext context, InstanceReference reference)
/// The parameter override value accessors.
private void AssignPropertyOverrides(IContext context, InstanceReference reference, IList propertyValues)
{
- var properties = reference.Instance.GetType().GetRuntimeProperties().FilterPublic(Settings.InjectNonPublic);
+ var properties = reference.Instance.GetType().GetProperties(this.Flags);
foreach (var propertyValue in propertyValues)
{
- string propertyName = propertyValue.Name;
+ var propertyName = propertyValue.Name;
var propertyInfo = properties.FirstOrDefault(property => string.Equals(property.Name, propertyName, StringComparison.Ordinal));
if (propertyInfo == null)
@@ -84,7 +106,7 @@ private void AssignPropertyOverrides(IContext context, InstanceReference referen
}
var target = new PropertyInjectionDirective(propertyInfo, this.InjectorFactory.Create(propertyInfo));
- object value = this.GetValue(context, target.Target, propertyValues);
+ var value = this.GetValue(context, target.Target, propertyValues);
target.Injector(reference.Instance, value);
}
}
diff --git a/src/Ninject/Activation/Strategies/StartableStrategy.cs b/src/Ninject/Activation/Strategies/StartableStrategy.cs
index 01c6ea58..5969eeda 100644
--- a/src/Ninject/Activation/Strategies/StartableStrategy.cs
+++ b/src/Ninject/Activation/Strategies/StartableStrategy.cs
@@ -1,15 +1,25 @@
-#region License
-//
-// Author: Nate Kohari
-// Copyright (c) 2007-2010, Enkari, Ltd.
-//
-// Dual-licensed under the Apache License, Version 2.0, and the Microsoft Public License (Ms-PL).
-// See the file LICENSE.txt for details.
-//
-#endregion
-#region Using Directives
-using System;
-#endregion
+//-------------------------------------------------------------------------------------------------
+//
+// Copyright (c) 2007-2010, Enkari, Ltd.
+// Copyright (c) 2010-2016, Ninject Project Contributors
+// Authors: Nate Kohari (nate@enkari.com)
+// Remo Gloor (remo.gloor@gmail.com)
+//
+// 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.
+//
+//-------------------------------------------------------------------------------------------------
namespace Ninject.Activation.Strategies
{
diff --git a/src/Ninject/ActivationException.cs b/src/Ninject/ActivationException.cs
index 7d87a2d4..3820af8d 100644
--- a/src/Ninject/ActivationException.cs
+++ b/src/Ninject/ActivationException.cs
@@ -1,44 +1,62 @@
-#region License
-//
-// Author: Nate Kohari
-// Copyright (c) 2007-2010, Enkari, Ltd.
-//
-// Dual-licensed under the Apache License, Version 2.0, and the Microsoft Public License (Ms-PL).
-// See the file LICENSE.txt for details.
-//
-#endregion
-#region Using Directives
-using System;
-#if !NO_EXCEPTION_SERIALIZATION
-using System.Runtime.Serialization;
-#endif
-#endregion
+//-------------------------------------------------------------------------------------------------
+//
+// Copyright (c) 2007-2010, Enkari, Ltd.
+// Copyright (c) 2010-2016, Ninject Project Contributors
+// Authors: Nate Kohari (nate@enkari.com)
+// Remo Gloor (remo.gloor@gmail.com)
+//
+// 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.
+//
+//-------------------------------------------------------------------------------------------------
namespace Ninject
{
+ using System;
+#if !NO_EXCEPTION_SERIALIZATION
+ using System.Runtime.Serialization;
+#endif
+
///
- /// Indicates that an error occured during activation of an instance.
+ /// Indicates that an error occurred during activation of an instance.
///
-
public class ActivationException : Exception
{
///
/// Initializes a new instance of the class.
///
- public ActivationException() { }
+ public ActivationException()
+ {
+ }
///
/// Initializes a new instance of the class.
///
/// The exception message.
- public ActivationException(string message) : base(message) { }
+ public ActivationException(string message)
+ : base(message)
+ {
+ }
///
/// Initializes a new instance of the class.
///
/// The exception message.
/// The inner exception.
- public ActivationException(string message, Exception innerException) : base(message, innerException) { }
-
+ public ActivationException(string message, Exception innerException)
+ : base(message, innerException)
+ {
+ }
}
}
\ No newline at end of file
diff --git a/src/Ninject/Attributes/ConstraintAttribute.cs b/src/Ninject/Attributes/ConstraintAttribute.cs
index 6460ed57..1578f40f 100644
--- a/src/Ninject/Attributes/ConstraintAttribute.cs
+++ b/src/Ninject/Attributes/ConstraintAttribute.cs
@@ -1,19 +1,31 @@
-#region License
-//
-// Author: Nate Kohari
-// Copyright (c) 2007-2010, Enkari, Ltd.
-//
-// Dual-licensed under the Apache License, Version 2.0, and the Microsoft Public License (Ms-PL).
-// See the file LICENSE.txt for details.
-//
-#endregion
-#region Using Directives
-using System;
-using Ninject.Planning.Bindings;
-#endregion
+//-------------------------------------------------------------------------------------------------
+//
+// Copyright (c) 2007-2010, Enkari, Ltd.
+// Copyright (c) 2010-2016, Ninject Project Contributors
+// Authors: Nate Kohari (nate@enkari.com)
+// Remo Gloor (remo.gloor@gmail.com)
+//
+// 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.
+//
+//-------------------------------------------------------------------------------------------------
namespace Ninject
{
+ using System;
+ using Ninject.Planning.Bindings;
+
///
/// Defines a constraint on the decorated member.
///
@@ -27,4 +39,4 @@ public abstract class ConstraintAttribute : Attribute
/// True if the metadata matches; otherwise false.
public abstract bool Matches(IBindingMetadata metadata);
}
-}
+}
\ No newline at end of file
diff --git a/src/Ninject/Attributes/InjectAttribute.cs b/src/Ninject/Attributes/InjectAttribute.cs
index d3b0535d..f54e5f7b 100644
--- a/src/Ninject/Attributes/InjectAttribute.cs
+++ b/src/Ninject/Attributes/InjectAttribute.cs
@@ -1,22 +1,38 @@
-#region License
-//
-// Author: Nate Kohari
-// Copyright (c) 2007-2010, Enkari, Ltd.
-//
-// Dual-licensed under the Apache License, Version 2.0, and the Microsoft Public License (Ms-PL).
-// See the file LICENSE.txt for details.
-//
-#endregion
-#region Using Directives
-using System;
-#endregion
+//-------------------------------------------------------------------------------------------------
+//
+// Copyright (c) 2007-2010, Enkari, Ltd.
+// Copyright (c) 2010-2016, Ninject Project Contributors
+// Authors: Nate Kohari (nate@enkari.com)
+// Remo Gloor (remo.gloor@gmail.com)
+//
+// 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.
+//
+//-------------------------------------------------------------------------------------------------
namespace Ninject
{
+ using System;
+
///
/// Indicates that the decorated member should be injected.
///
- [AttributeUsage(AttributeTargets.Constructor | AttributeTargets.Method | AttributeTargets.Property | AttributeTargets.Field,
- AllowMultiple = false, Inherited = true)]
- public class InjectAttribute : Attribute { }
-}
+ [AttributeUsage(
+ AttributeTargets.Constructor | AttributeTargets.Method | AttributeTargets.Property | AttributeTargets.Field,
+ AllowMultiple = false,
+ Inherited = true)]
+ public class InjectAttribute : Attribute
+ {
+ }
+}
\ No newline at end of file
diff --git a/src/Ninject/Attributes/NamedAttribute.cs b/src/Ninject/Attributes/NamedAttribute.cs
index a695d0a6..a908b1a5 100644
--- a/src/Ninject/Attributes/NamedAttribute.cs
+++ b/src/Ninject/Attributes/NamedAttribute.cs
@@ -1,41 +1,53 @@
-#region License
-//
-// Author: Nate Kohari
-// Copyright (c) 2007-2010, Enkari, Ltd.
-//
-// Dual-licensed under the Apache License, Version 2.0, and the Microsoft Public License (Ms-PL).
-// See the file LICENSE.txt for details.
-//
-#endregion
-#region Using Directives
-using System;
-using Ninject.Infrastructure;
-using Ninject.Planning.Bindings;
-#endregion
+//-------------------------------------------------------------------------------------------------
+//
+// Copyright (c) 2007-2010, Enkari, Ltd.
+// Copyright (c) 2010-2016, Ninject Project Contributors
+// Authors: Nate Kohari (nate@enkari.com)
+// Remo Gloor (remo.gloor@gmail.com)
+//
+// 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.
+//
+//-------------------------------------------------------------------------------------------------
namespace Ninject
{
+ using System.Diagnostics.Contracts;
+ using Ninject.Infrastructure;
+ using Ninject.Planning.Bindings;
+
///
/// Indicates that the decorated member should only be injected using binding(s) registered
/// with the specified name.
///
public class NamedAttribute : ConstraintAttribute
{
- ///
- /// Gets the binding name.
- ///
- public string Name { get; private set; }
-
///
/// Initializes a new instance of the class.
///
/// The name of the binding(s) to use.
public NamedAttribute(string name)
{
- Ensure.ArgumentNotNullOrEmpty(name, "name");
- Name = name;
+ Contract.Requires(name != null);
+ this.Name = name;
}
+ ///
+ /// Gets the binding name.
+ ///
+ public string Name { get; private set; }
+
///
/// Determines whether the specified binding metadata matches the constraint.
///
@@ -43,8 +55,8 @@ public NamedAttribute(string name)
/// True if the metadata matches; otherwise false.
public override bool Matches(IBindingMetadata metadata)
{
- Ensure.ArgumentNotNull(metadata, "metadata");
- return metadata.Name == Name;
+ Contract.Requires(metadata != null);
+ return metadata.Name == this.Name;
}
}
-}
+}
\ No newline at end of file
diff --git a/src/Ninject/Attributes/OptionalAttribute.cs b/src/Ninject/Attributes/OptionalAttribute.cs
index 99fd94fe..23c612b8 100644
--- a/src/Ninject/Attributes/OptionalAttribute.cs
+++ b/src/Ninject/Attributes/OptionalAttribute.cs
@@ -1,22 +1,38 @@
-#region License
-//
-// Author: Nate Kohari
-// Copyright (c) 2007-2010, Enkari, Ltd.
-//
-// Dual-licensed under the Apache License, Version 2.0, and the Microsoft Public License (Ms-PL).
-// See the file LICENSE.txt for details.
-//
-#endregion
-#region Using Directives
-using System;
-#endregion
+//-------------------------------------------------------------------------------------------------
+//
+// Copyright (c) 2007-2010, Enkari, Ltd.
+// Copyright (c) 2010-2016, Ninject Project Contributors
+// Authors: Nate Kohari (nate@enkari.com)
+// Remo Gloor (remo.gloor@gmail.com)
+//
+// 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.
+//
+//-------------------------------------------------------------------------------------------------
namespace Ninject
{
+ using System;
+
///
/// Indicates that the decorated member represents an optional dependency.
///
- [AttributeUsage(AttributeTargets.Constructor | AttributeTargets.Method | AttributeTargets.Property | AttributeTargets.Parameter,
- AllowMultiple = false, Inherited = true)]
- public class OptionalAttribute : Attribute { }
-}
+ [AttributeUsage(
+ AttributeTargets.Constructor | AttributeTargets.Method | AttributeTargets.Property | AttributeTargets.Parameter,
+ AllowMultiple = false,
+ Inherited = true)]
+ public class OptionalAttribute : Attribute
+ {
+ }
+}
\ No newline at end of file
diff --git a/src/Ninject/BindingPrecedenceComparer.cs b/src/Ninject/BindingPrecedenceComparer.cs
index 5e4b8171..92ac7459 100644
--- a/src/Ninject/BindingPrecedenceComparer.cs
+++ b/src/Ninject/BindingPrecedenceComparer.cs
@@ -1,4 +1,26 @@
-
+//-------------------------------------------------------------------------------------------------
+//
+// Copyright (c) 2007-2010, Enkari, Ltd.
+// Copyright (c) 2010-2016, Ninject Project Contributors
+// Authors: Nate Kohari (nate@enkari.com)
+// Remo Gloor (remo.gloor@gmail.com)
+//
+// 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.
+//
+//-------------------------------------------------------------------------------------------------
+
namespace Ninject
{
using System;
diff --git a/src/Ninject/Components/ComponentContainer.cs b/src/Ninject/Components/ComponentContainer.cs
index a918a093..0d50d85e 100644
--- a/src/Ninject/Components/ComponentContainer.cs
+++ b/src/Ninject/Components/ComponentContainer.cs
@@ -1,32 +1,44 @@
-#region License
-//
-// Author: Nate Kohari
-// Copyright (c) 2007-2010, Enkari, Ltd.
-//
-// Dual-licensed under the Apache License, Version 2.0, and the Microsoft Public License (Ms-PL).
-// See the file LICENSE.txt for details.
-//
-#endregion
-#region Using Directives
-using System;
-using System.Collections.Generic;
-using System.Linq;
-using System.Reflection;
-using Ninject.Infrastructure;
-using Ninject.Infrastructure.Disposal;
-using Ninject.Infrastructure.Introspection;
-using Ninject.Infrastructure.Language;
-#endregion
+//-------------------------------------------------------------------------------------------------
+//
+// Copyright (c) 2007-2010, Enkari, Ltd.
+// Copyright (c) 2010-2016, Ninject Project Contributors
+// Authors: Nate Kohari (nate@enkari.com)
+// Remo Gloor (remo.gloor@gmail.com)
+//
+// 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.
+//
+//-------------------------------------------------------------------------------------------------
namespace Ninject.Components
{
+ using System;
+ using System.Collections.Generic;
+ using System.Linq;
+ using System.Reflection;
+ using Ninject.Infrastructure;
+ using Ninject.Infrastructure.Disposal;
+ using Ninject.Infrastructure.Introspection;
+ using Ninject.Infrastructure.Language;
+
///
/// An internal container that manages and resolves components that contribute to Ninject.
///
public class ComponentContainer : DisposableObject, IComponentContainer
{
- private readonly Multimap _mappings = new Multimap();
- private readonly Dictionary _instances = new Dictionary();
+ private readonly Multimap mappings = new Multimap();
+ private readonly Dictionary instances = new Dictionary();
private readonly HashSet> transients = new HashSet>();
///
@@ -37,15 +49,18 @@ public class ComponentContainer : DisposableObject, IComponentContainer
///
/// Releases resources held by the object.
///
+ /// True if called manually, otherwise by GC.
public override void Dispose(bool disposing)
{
- if (disposing && !IsDisposed)
+ if (disposing && !this.IsDisposed)
{
- foreach (INinjectComponent instance in _instances.Values)
+ foreach (INinjectComponent instance in this.instances.Values)
+ {
instance.Dispose();
+ }
- _mappings.Clear();
- _instances.Clear();
+ this.mappings.Clear();
+ this.instances.Clear();
}
base.Dispose(disposing);
@@ -60,7 +75,7 @@ public override void Dispose(bool disposing)
where TComponent : INinjectComponent
where TImplementation : TComponent, INinjectComponent
{
- _mappings.Add(typeof(TComponent), typeof(TImplementation));
+ this.mappings.Add(typeof(TComponent), typeof(TImplementation));
}
///
@@ -75,7 +90,7 @@ public override void Dispose(bool disposing)
this.Add();
this.transients.Add(new KeyValuePair(typeof(TComponent), typeof(TImplementation)));
}
-
+
///
/// Removes all registrations for the specified component.
///
@@ -83,7 +98,7 @@ public override void Dispose(bool disposing)
public void RemoveAll()
where T : INinjectComponent
{
- RemoveAll(typeof(T));
+ this.RemoveAll(typeof(T));
}
///
@@ -96,28 +111,33 @@ public void RemoveAll()
where TImplementation : T
{
var implementation = typeof(TImplementation);
- if (_instances.ContainsKey(implementation))
- _instances[implementation].Dispose();
+ if (this.instances.ContainsKey(implementation))
+ {
+ this.instances[implementation].Dispose();
+ }
- _instances.Remove(implementation);
+ this.instances.Remove(implementation);
- _mappings.Remove(typeof(T), typeof(TImplementation));
+ this.mappings.Remove(typeof(T), typeof(TImplementation));
}
+
///
/// Removes all registrations for the specified component.
///
/// The component type.
public void RemoveAll(Type component)
{
- foreach (Type implementation in _mappings[component])
+ foreach (Type implementation in this.mappings[component])
{
- if (_instances.ContainsKey(implementation))
- _instances[implementation].Dispose();
+ if (this.instances.ContainsKey(implementation))
+ {
+ this.instances[implementation].Dispose();
+ }
- _instances.Remove(implementation);
+ this.instances.Remove(implementation);
}
- _mappings.RemoveAll(component);
+ this.mappings.RemoveAll(component);
}
///
@@ -128,7 +148,7 @@ public void RemoveAll(Type component)
public T Get()
where T : INinjectComponent
{
- return (T) Get(typeof(T));
+ return (T)this.Get(typeof(T));
}
///
@@ -139,7 +159,7 @@ public T Get()
public IEnumerable GetAll()
where T : INinjectComponent
{
- return GetAll(typeof(T)).Cast();
+ return this.GetAll(typeof(T)).Cast();
}
///
@@ -150,23 +170,30 @@ public IEnumerable GetAll()
public object Get(Type component)
{
if (component == typeof(IKernelConfiguration))
- return KernelConfiguration;
+ {
+ return this.KernelConfiguration;
+ }
if (component.GetTypeInfo().IsGenericType)
{
- Type gtd = component.GetGenericTypeDefinition();
- Type argument = component.GetTypeInfo().GenericTypeArguments[0];
+ var gtd = component.GetGenericTypeDefinition();
+ var argument = component.GetTypeInfo().GenericTypeArguments[0];
var info = gtd.GetTypeInfo();
- if(info.IsInterface && typeof(IEnumerable<>).GetTypeInfo().IsAssignableFrom(info))
- return GetAll(argument).CastSlow(argument);
+ if (info.IsInterface && typeof(IEnumerable<>).GetTypeInfo().IsAssignableFrom(info))
+ {
+ return this.GetAll(argument).CastSlow(argument);
+ }
}
- Type implementation = _mappings[component].FirstOrDefault();
+
+ var implementation = this.mappings[component].FirstOrDefault();
if (implementation == null)
+ {
throw new InvalidOperationException(ExceptionFormatter.NoSuchComponentRegistered(component));
+ }
- return ResolveInstance(component, implementation);
+ return this.ResolveInstance(component, implementation);
}
///
@@ -176,31 +203,47 @@ public object Get(Type component)
/// A series of instances of the specified component.
public IEnumerable GetAll(Type component)
{
- return _mappings[component]
- .Select(implementation => ResolveInstance(component, implementation));
+ return this.mappings[component]
+ .Select(implementation => this.ResolveInstance(component, implementation));
+ }
+
+ private static ConstructorInfo SelectConstructor(Type component, Type implementation)
+ {
+ var constructor =
+ implementation.GetTypeInfo().DeclaredConstructors.Where(c => c.IsPublic && !c.IsStatic).OrderByDescending(c => c.GetParameters().Length).
+ FirstOrDefault();
+
+ if (constructor == null)
+ {
+ throw new InvalidOperationException(ExceptionFormatter.NoConstructorsAvailableForComponent(component, implementation));
+ }
+
+ return constructor;
}
private object ResolveInstance(Type component, Type implementation)
{
- lock (_instances)
- return _instances.ContainsKey(implementation) ? _instances[implementation] : CreateNewInstance(component, implementation);
+ lock (this.instances)
+ {
+ return this.instances.ContainsKey(implementation) ? this.instances[implementation] : this.CreateNewInstance(component, implementation);
+ }
}
private object CreateNewInstance(Type component, Type implementation)
{
- ConstructorInfo constructor = SelectConstructor(component, implementation);
- var arguments = constructor.GetParameters().Select(parameter => Get(parameter.ParameterType)).ToArray();
+ var constructor = SelectConstructor(component, implementation);
+ var arguments = constructor.GetParameters().Select(parameter => this.Get(parameter.ParameterType)).ToArray();
try
{
var instance = constructor.Invoke(arguments) as INinjectComponent;
// Todo: Clone Settings during kernel build (is this still important? Can clone settings now)
- instance.Settings = KernelConfiguration.Settings.Clone();
+ instance.Settings = this.KernelConfiguration.Settings.Clone();
if (!this.transients.Contains(new KeyValuePair(component, implementation)))
{
- _instances.Add(implementation, instance);
+ this.instances.Add(implementation, instance);
}
return instance;
@@ -211,34 +254,5 @@ private object CreateNewInstance(Type component, Type implementation)
return null;
}
}
-
- private static ConstructorInfo SelectConstructor(Type component, Type implementation)
- {
- var constructor =
- implementation.GetTypeInfo().DeclaredConstructors.Where(c => c.IsPublic && !c.IsStatic).OrderByDescending(c => c.GetParameters().Length).
- FirstOrDefault();
-
- if (constructor == null)
- throw new InvalidOperationException(ExceptionFormatter.NoConstructorsAvailableForComponent(component, implementation));
-
- return constructor;
- }
-
-#if MONO
- private class HashSet
- {
- private IDictionary data = new Dictionary();
-
- public void Add(T o)
- {
- this.data.Add(o, true);
- }
-
- public bool Contains(T o)
- {
- return this.data.ContainsKey(o);
- }
- }
-#endif
}
}
\ No newline at end of file
diff --git a/src/Ninject/Components/IComponentContainer.cs b/src/Ninject/Components/IComponentContainer.cs
index 6709dbed..3448d23d 100644
--- a/src/Ninject/Components/IComponentContainer.cs
+++ b/src/Ninject/Components/IComponentContainer.cs
@@ -1,26 +1,38 @@
-#region License
-//
-// Author: Nate Kohari
-// Copyright (c) 2007-2010, Enkari, Ltd.
-//
-// Dual-licensed under the Apache License, Version 2.0, and the Microsoft Public License (Ms-PL).
-// See the file LICENSE.txt for details.
-//
-#endregion
-#region Using Directives
-using System;
-using System.Collections.Generic;
-#endregion
+//-------------------------------------------------------------------------------------------------
+//
+// Copyright (c) 2007-2010, Enkari, Ltd.
+// Copyright (c) 2010-2016, Ninject Project Contributors
+// Authors: Nate Kohari (nate@enkari.com)
+// Remo Gloor (remo.gloor@gmail.com)
+//
+// 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.
+//
+//-------------------------------------------------------------------------------------------------
namespace Ninject.Components
{
+ using System;
+ using System.Collections.Generic;
+
///
/// An internal container that manages and resolves components that contribute to Ninject.
///
public interface IComponentContainer : IDisposable
{
///
- /// Get or sets the kernel configuration
+ /// Gets or sets the kernel configuration
///
IKernelConfiguration KernelConfiguration { get; set; }
@@ -37,7 +49,8 @@ public interface IComponentContainer : IDisposable
/// Removes all registrations for the specified component.
///
/// The component type.
- void RemoveAll() where T : INinjectComponent;
+ void RemoveAll()
+ where T : INinjectComponent;
///
/// Removes all registrations for the specified component.
@@ -50,21 +63,25 @@ public interface IComponentContainer : IDisposable
///
/// The component type.
/// The implementation type.
- void Remove() where T : INinjectComponent where TImplementation : T;
+ void Remove()
+ where T : INinjectComponent
+ where TImplementation : T;
///
/// Gets one instance of the specified component.
///
/// The component type.
/// The instance of the component.
- T Get() where T : INinjectComponent;
+ T Get()
+ where T : INinjectComponent;
///
/// Gets all available instances of the specified component.
///
/// The component type.
/// A series of instances of the specified component.
- IEnumerable GetAll() where T : INinjectComponent;
+ IEnumerable GetAll()
+ where T : INinjectComponent;
///
/// Gets one instance of the specified component.
diff --git a/src/Ninject/Components/INinjectComponent.cs b/src/Ninject/Components/INinjectComponent.cs
index 41d8faee..5c56edd7 100644
--- a/src/Ninject/Components/INinjectComponent.cs
+++ b/src/Ninject/Components/INinjectComponent.cs
@@ -1,18 +1,30 @@
-#region License
-//
-// Author: Nate Kohari
-// Copyright (c) 2007-2010, Enkari, Ltd.
-//
-// Dual-licensed under the Apache License, Version 2.0, and the Microsoft Public License (Ms-PL).
-// See the file LICENSE.txt for details.
-//
-#endregion
-#region Using Directives
-using System;
-#endregion
+//-------------------------------------------------------------------------------------------------
+//
+// Copyright (c) 2007-2010, Enkari, Ltd.
+// Copyright (c) 2010-2016, Ninject Project Contributors
+// Authors: Nate Kohari (nate@enkari.com)
+// Remo Gloor (remo.gloor@gmail.com)
+//
+// 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.
+//
+//-------------------------------------------------------------------------------------------------
namespace Ninject.Components
{
+ using System;
+
///
/// A component that contributes to the internals of Ninject.
///
diff --git a/src/Ninject/Components/NinjectComponent.cs b/src/Ninject/Components/NinjectComponent.cs
index ea78e7bc..2f517f63 100644
--- a/src/Ninject/Components/NinjectComponent.cs
+++ b/src/Ninject/Components/NinjectComponent.cs
@@ -1,19 +1,30 @@
-#region License
-//
-// Author: Nate Kohari
-// Copyright (c) 2007-2010, Enkari, Ltd.
-//
-// Dual-licensed under the Apache License, Version 2.0, and the Microsoft Public License (Ms-PL).
-// See the file LICENSE.txt for details.
-//
-#endregion
-#region Using Directives
-using System;
-using Ninject.Infrastructure.Disposal;
-#endregion
+//-------------------------------------------------------------------------------------------------
+//
+// Copyright (c) 2007-2010, Enkari, Ltd.
+// Copyright (c) 2010-2016, Ninject Project Contributors
+// Authors: Nate Kohari (nate@enkari.com)
+// Remo Gloor (remo.gloor@gmail.com)
+//
+// 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.
+//
+//-------------------------------------------------------------------------------------------------
namespace Ninject.Components
{
+ using Ninject.Infrastructure.Disposal;
+
///
/// A component that contributes to the internals of Ninject.
///
diff --git a/src/Ninject/GlobalKernelRegistration.cs b/src/Ninject/GlobalKernelRegistration.cs
index 432b99eb..b3506831 100644
--- a/src/Ninject/GlobalKernelRegistration.cs
+++ b/src/Ninject/GlobalKernelRegistration.cs
@@ -1,8 +1,11 @@
//-------------------------------------------------------------------------------
+//-------------------------------------------------------------------------------------------------
//
-// Copyright (c) 2009-2011 Ninject Project Contributors
-// Authors: Remo Gloor (remo.gloor@gmail.com)
-//
+// Copyright (c) 2007-2010, Enkari, Ltd.
+// Copyright (c) 2010-2016, Ninject Project Contributors
+// Authors: Nate Kohari (nate@enkari.com)
+// Remo Gloor (remo.gloor@gmail.com)
+//
// 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
@@ -32,15 +35,17 @@ namespace Ninject
///
public abstract class GlobalKernelRegistration
{
- private static readonly ReaderWriterLockSlim kernelRegistrationsLock = new ReaderWriterLockSlim();
+ private static readonly ReaderWriterLockSlim KernelRegistrationsLock = new ReaderWriterLockSlim();
- private static readonly IDictionary kernelRegistrations = new Dictionary();
+ private static readonly IDictionary KernelRegistrations = new Dictionary();
+ ///
+ /// Registers the kernel for the specified type.
+ ///
+ /// The .
+ /// The service type.
internal static void RegisterKernelForType(IReadOnlyKernel kernel, Type type)
{
- #if PCL
- throw new NotImplementedException();
-#else
var registration = GetRegistrationForType(type);
registration.KernelLock.EnterReadLock();
@@ -51,21 +56,19 @@ internal static void RegisterKernelForType(IReadOnlyKernel kernel, Type type)
}
finally
{
-
registration.KernelLock.ExitReadLock();
-
}
-#endif
}
+ ///
+ /// Un-registers the kernel for the specified type.
+ ///
+ /// The .
+ /// The service type.
internal static void UnregisterKernelForType(IReadOnlyKernel kernel, Type type)
{
-#if PCL
- throw new NotImplementedException();
-#else
var registration = GetRegistrationForType(type);
RemoveKernels(registration, registration.Kernels.Where(reference => reference.Target == kernel || !reference.IsAlive));
-#endif
}
///
@@ -74,16 +77,11 @@ internal static void UnregisterKernelForType(IReadOnlyKernel kernel, Type type)
/// The action.
protected void MapKernels(Action action)
{
-#if PCL
- throw new NotImplementedException();
-#else
- bool requiresCleanup = false;
+ var requiresCleanup = false;
var registration = GetRegistrationForType(this.GetType());
registration.KernelLock.EnterReadLock();
-
-
try
{
foreach (var weakReference in registration.Kernels)
@@ -101,24 +99,17 @@ protected void MapKernels(Action action)
}
finally
{
-
registration.KernelLock.ExitReadLock();
-
}
if (requiresCleanup)
{
RemoveKernels(registration, registration.Kernels.Where(reference => !reference.IsAlive));
}
-#endif
}
-
+
private static void RemoveKernels(Registration registration, IEnumerable references)
{
-#if PCL
- throw new NotImplementedException();
-#else
-
registration.KernelLock.ExitReadLock();
try
@@ -130,78 +121,63 @@ private static void RemoveKernels(Registration registration, IEnumerable();
}
-
public ReaderWriterLockSlim KernelLock { get; private set; }
public IList Kernels { get; private set; }
-#endif
}
}
}
\ No newline at end of file
diff --git a/src/Ninject/GlobalKernelRegistrationModule.cs b/src/Ninject/GlobalKernelRegistrationModule.cs
index 1ab05fa2..8b7a8800 100644
--- a/src/Ninject/GlobalKernelRegistrationModule.cs
+++ b/src/Ninject/GlobalKernelRegistrationModule.cs
@@ -1,8 +1,10 @@
-//-------------------------------------------------------------------------------
+//-------------------------------------------------------------------------------------------------
//
-// Copyright (c) 2009-2011 Ninject Project Contributors
-// Authors: Remo Gloor (remo.gloor@gmail.com)
-//
+// Copyright (c) 2007-2010, Enkari, Ltd.
+// Copyright (c) 2010-2016, Ninject Project Contributors
+// Authors: Nate Kohari (nate@enkari.com)
+// Remo Gloor (remo.gloor@gmail.com)
+//
// 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
@@ -17,8 +19,7 @@
// See the License for the specific language governing permissions and
// limitations under the License.
//
-//-------------------------------------------------------------------------------
-
+//-------------------------------------------------------------------------------------------------
/* Temporary disabled feature
#if !SILVERLIGHT
diff --git a/src/Ninject/IBindingPrecedenceComparer.cs b/src/Ninject/IBindingPrecedenceComparer.cs
index 5bb1ba2d..3b6d4018 100644
--- a/src/Ninject/IBindingPrecedenceComparer.cs
+++ b/src/Ninject/IBindingPrecedenceComparer.cs
@@ -1,4 +1,27 @@
-namespace Ninject
+//-------------------------------------------------------------------------------------------------
+//
+// Copyright (c) 2007-2010, Enkari, Ltd.
+// Copyright (c) 2010-2016, Ninject Project Contributors
+// Authors: Nate Kohari (nate@enkari.com)
+// Remo Gloor (remo.gloor@gmail.com)
+//
+// 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.
+//
+//-------------------------------------------------------------------------------------------------
+
+namespace Ninject
{
using System.Collections.Generic;
diff --git a/src/Ninject/IHaveNinjectComponents.cs b/src/Ninject/IHaveNinjectComponents.cs
index 96e01c9e..23f650b1 100644
--- a/src/Ninject/IHaveNinjectComponents.cs
+++ b/src/Ninject/IHaveNinjectComponents.cs
@@ -1,7 +1,30 @@
-using Ninject.Components;
+//-------------------------------------------------------------------------------------------------
+//
+// Copyright (c) 2007-2010, Enkari, Ltd.
+// Copyright (c) 2010-2016, Ninject Project Contributors
+// Authors: Nate Kohari (nate@enkari.com)
+// Remo Gloor (remo.gloor@gmail.com)
+//
+// 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.
+//
+//-------------------------------------------------------------------------------------------------
namespace Ninject
{
+ using Ninject.Components;
+
///
/// Provides access to Ninject components.
///
@@ -10,6 +33,6 @@ public interface IHaveNinjectComponents
///
/// Gets the component container, which holds components that contribute to Ninject.
///
- IComponentContainer Components { get; }
+ IComponentContainer Components { get; }
}
}
\ No newline at end of file
diff --git a/src/Ninject/IHaveNinjectSettings.cs b/src/Ninject/IHaveNinjectSettings.cs
index 05909d17..c792c400 100644
--- a/src/Ninject/IHaveNinjectSettings.cs
+++ b/src/Ninject/IHaveNinjectSettings.cs
@@ -1,3 +1,26 @@
+//-------------------------------------------------------------------------------------------------
+//
+// Copyright (c) 2007-2010, Enkari, Ltd.
+// Copyright (c) 2010-2016, Ninject Project Contributors
+// Authors: Nate Kohari (nate@enkari.com)
+// Remo Gloor (remo.gloor@gmail.com)
+//
+// 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.
+//
+//-------------------------------------------------------------------------------------------------
+
namespace Ninject
{
///
@@ -8,6 +31,6 @@ public interface IHaveNinjectSettings
///
/// Gets the kernel settings.
///
- INinjectSettings Settings { get; }
+ INinjectSettings Settings { get; }
}
}
\ No newline at end of file
diff --git a/src/Ninject/IInitializable.cs b/src/Ninject/IInitializable.cs
index c1d22862..817dc7ee 100644
--- a/src/Ninject/IInitializable.cs
+++ b/src/Ninject/IInitializable.cs
@@ -1,15 +1,25 @@
-#region License
-//
-// Author: Nate Kohari
-// Copyright (c) 2007-2010, Enkari, Ltd.
-//
-// Dual-licensed under the Apache License, Version 2.0, and the Microsoft Public License (Ms-PL).
-// See the file LICENSE.txt for details.
-//
-#endregion
-#region Using Directives
-using System;
-#endregion
+//-------------------------------------------------------------------------------------------------
+//
+// Copyright (c) 2007-2010, Enkari, Ltd.
+// Copyright (c) 2010-2016, Ninject Project Contributors
+// Authors: Nate Kohari (nate@enkari.com)
+// Remo Gloor (remo.gloor@gmail.com)
+//
+// 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.
+//
+//-------------------------------------------------------------------------------------------------
namespace Ninject
{
@@ -23,4 +33,4 @@ public interface IInitializable
///
void Initialize();
}
-}
+}
\ No newline at end of file
diff --git a/src/Ninject/IKernel.cs b/src/Ninject/IKernel.cs
index 6745d77d..c4bf8b9a 100644
--- a/src/Ninject/IKernel.cs
+++ b/src/Ninject/IKernel.cs
@@ -1,23 +1,31 @@
-#region License
-//
-// Author: Nate Kohari
-// Copyright (c) 2007-2010, Enkari, Ltd.
-//
-// Dual-licensed under the Apache License, Version 2.0, and the Microsoft Public License (Ms-PL).
-// See the file LICENSE.txt for details.
-//
-#endregion
-#region Using Directives
-using System;
-using System.Collections.Generic;
-using Ninject.Activation.Blocks;
-using Ninject.Parameters;
-using Ninject.Planning.Bindings;
-
-#endregion
+//-------------------------------------------------------------------------------------------------
+//
+// Copyright (c) 2007-2010, Enkari, Ltd.
+// Copyright (c) 2010-2016, Ninject Project Contributors
+// Authors: Nate Kohari (nate@enkari.com)
+// Remo Gloor (remo.gloor@gmail.com)
+//
+// 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.
+//
+//-------------------------------------------------------------------------------------------------
namespace Ninject
{
+ using System;
+ using Planning.Bindings;
+
///
/// A super-factory that can create objects of all kinds, following hints provided by s.
///
@@ -25,4 +33,4 @@ namespace Ninject
public interface IKernel : IKernelConfiguration, IReadOnlyKernel
{
}
-}
+}
\ No newline at end of file
diff --git a/src/Ninject/IKernelConfiguration.cs b/src/Ninject/IKernelConfiguration.cs
index a6e4b7b6..69e54276 100644
--- a/src/Ninject/IKernelConfiguration.cs
+++ b/src/Ninject/IKernelConfiguration.cs
@@ -1,12 +1,35 @@
-using System;
-using System.Collections.Generic;
-using System.Reflection;
-using Ninject.Modules;
-using Ninject.Planning.Bindings;
-using Ninject.Syntax;
+//-------------------------------------------------------------------------------------------------
+//
+// Copyright (c) 2007-2010, Enkari, Ltd.
+// Copyright (c) 2010-2016, Ninject Project Contributors
+// Authors: Nate Kohari (nate@enkari.com)
+// Remo Gloor (remo.gloor@gmail.com)
+//
+// 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.
+//
+//-------------------------------------------------------------------------------------------------
namespace Ninject
{
+ using System;
+ using System.Collections.Generic;
+ using System.Reflection;
+ using Ninject.Modules;
+ using Ninject.Planning.Bindings;
+ using Ninject.Syntax;
+
///
/// Configuration for a Ninject kernel.
///
diff --git a/src/Ninject/INinjectSettings.cs b/src/Ninject/INinjectSettings.cs
index 1fbe9540..6239e470 100644
--- a/src/Ninject/INinjectSettings.cs
+++ b/src/Ninject/INinjectSettings.cs
@@ -1,20 +1,31 @@
-#region License
-//
-// Author: Nate Kohari
-// Copyright (c) 2007-2010, Enkari, Ltd.
-//
-// Dual-licensed under the Apache License, Version 2.0, and the Microsoft Public License (Ms-PL).
-// See the file LICENSE.txt for details.
-//
-#endregion
-#region Using Directives
-using System;
-using Ninject.Activation;
-
-#endregion
+//-------------------------------------------------------------------------------------------------
+//
+// Copyright (c) 2007-2010, Enkari, Ltd.
+// Copyright (c) 2010-2016, Ninject Project Contributors
+// Authors: Nate Kohari (nate@enkari.com)
+// Remo Gloor (remo.gloor@gmail.com)
+//
+// 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.
+//
+//-------------------------------------------------------------------------------------------------
namespace Ninject
{
+ using System;
+ using Ninject.Activation;
+
///
/// Contains configuration options for Ninject.
///
@@ -47,22 +58,19 @@ public interface INinjectSettings
string[] ExtensionSearchPatterns { get; }
#endif //!NO_ASSEMBLY_SCANNING
-
///
/// Gets a value indicating whether Ninject should use reflection-based injection instead of
/// the (usually faster) lightweight code generation system.
///
bool UseReflectionBasedInjection { get; }
-
-
///
- /// Gets a value indicating whether Ninject should inject non public members.
+ /// Gets or sets a value indicating whether Ninject should inject non public members.
///
bool InjectNonPublic { get; set; }
///
- /// Gets a value indicating whether Ninject should inject private properties of base classes.
+ /// Gets or sets a value indicating whether Ninject should inject private properties of base classes.
///
///
/// Activating this setting has an impact on the performance. It is recommended not
@@ -70,7 +78,6 @@ public interface INinjectSettings
///
bool InjectParentPrivateProperties { get; set; }
-
///
/// Gets or sets a value indicating whether the activation cache is disabled.
/// If the activation cache is disabled less memory is used. But in some cases
@@ -112,4 +119,4 @@ public interface INinjectSettings
/// A new instance of the ninject settings
INinjectSettings Clone();
}
-}
+}
\ No newline at end of file
diff --git a/src/Ninject/IReadonlyKernel.cs b/src/Ninject/IReadonlyKernel.cs
index 32eae255..faa7063d 100644
--- a/src/Ninject/IReadonlyKernel.cs
+++ b/src/Ninject/IReadonlyKernel.cs
@@ -1,12 +1,33 @@
-using System;
-using System.Collections.Generic;
-using Ninject.Infrastructure.Disposal;
-using Ninject.Planning.Bindings;
-using Ninject.Syntax;
+//-------------------------------------------------------------------------------------------------
+//
+// Copyright (c) 2007-2010, Enkari, Ltd.
+// Copyright (c) 2010-2016, Ninject Project Contributors
+// Authors: Nate Kohari (nate@enkari.com)
+// Remo Gloor (remo.gloor@gmail.com)
+//
+// 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.
+//
+//-------------------------------------------------------------------------------------------------
namespace Ninject
{
- using Ninject.Selection;
+ using System;
+ using System.Collections.Generic;
+ using Ninject.Infrastructure.Disposal;
+ using Ninject.Planning.Bindings;
+ using Ninject.Syntax;
///
/// A kernel that is used to resolve instances and has a configuration that can't be changed anymore
diff --git a/src/Ninject/IStartable.cs b/src/Ninject/IStartable.cs
index 51119075..8c06239d 100644
--- a/src/Ninject/IStartable.cs
+++ b/src/Ninject/IStartable.cs
@@ -1,15 +1,25 @@
-#region License
-//
-// Author: Nate Kohari
-// Copyright (c) 2007-2010, Enkari, Ltd.
-//
-// Dual-licensed under the Apache License, Version 2.0, and the Microsoft Public License (Ms-PL).
-// See the file LICENSE.txt for details.
-//
-#endregion
-#region Using Directives
-using System;
-#endregion
+//-------------------------------------------------------------------------------------------------
+//
+// Copyright (c) 2007-2010, Enkari, Ltd.
+// Copyright (c) 2010-2016, Ninject Project Contributors
+// Authors: Nate Kohari (nate@enkari.com)
+// Remo Gloor (remo.gloor@gmail.com)
+//
+// 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.
+//
+//-------------------------------------------------------------------------------------------------
namespace Ninject
{
@@ -28,4 +38,4 @@ public interface IStartable
///
void Stop();
}
-}
+}
\ No newline at end of file
diff --git a/src/Ninject/Infrastructure/BaseWeakReference.cs b/src/Ninject/Infrastructure/BaseWeakReference.cs
deleted file mode 100644
index 7582671b..00000000
--- a/src/Ninject/Infrastructure/BaseWeakReference.cs
+++ /dev/null
@@ -1,60 +0,0 @@
-namespace Ninject.Infrastructure
-{
- using System;
-
- ///
- /// Inheritable weak reference base class for Silverlight
- ///
- public abstract class BaseWeakReference
- {
- private readonly WeakReference innerWeakReference;
-
- ///
- /// Initializes a new instance of the class.
- ///
- /// The target.
- protected BaseWeakReference(object target)
- {
- this.innerWeakReference = new WeakReference(target);
- }
-
- ///
- /// Initializes a new instance of the class.
- ///
- /// The target.
- /// if set to true [track resurrection].
- protected BaseWeakReference(object target, bool trackResurrection)
- {
- this.innerWeakReference = new WeakReference(target, trackResurrection);
- }
-
- ///
- /// Gets a value indicating whether this instance is alive.
- ///
- /// true if this instance is alive; otherwise, false.
- public bool IsAlive
- {
- get
- {
- return this.innerWeakReference.IsAlive;
- }
- }
-
- ///
- /// Gets or sets the target of this weak reference.
- ///
- /// The target of this weak reference.
- public object Target
- {
- get
- {
- return this.innerWeakReference.Target;
- }
-
- set
- {
- this.innerWeakReference.Target = value;
- }
- }
- }
-}
\ No newline at end of file
diff --git a/src/Ninject/Infrastructure/Disposal/DisposableObject.cs b/src/Ninject/Infrastructure/Disposal/DisposableObject.cs
index 4794dfd2..f246846e 100644
--- a/src/Ninject/Infrastructure/Disposal/DisposableObject.cs
+++ b/src/Ninject/Infrastructure/Disposal/DisposableObject.cs
@@ -1,23 +1,48 @@
-#region License
-//
-// Author: Nate Kohari
-// Copyright (c) 2007-2010, Enkari, Ltd.
-//
-// Dual-licensed under the Apache License, Version 2.0, and the Microsoft Public License (Ms-PL).
-// See the file LICENSE.txt for details.
-//
-#endregion
-#region Using Directives
-using System;
-#endregion
+//-------------------------------------------------------------------------------------------------
+//
+// Copyright (c) 2007-2010, Enkari, Ltd.
+// Copyright (c) 2010-2016, Ninject Project Contributors
+// Authors: Nate Kohari (nate@enkari.com)
+// Remo Gloor (remo.gloor@gmail.com)
+//
+// 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.
+//
+//-------------------------------------------------------------------------------------------------
namespace Ninject.Infrastructure.Disposal
{
+ using System;
+
///
/// An object that notifies when it is disposed.
///
- public abstract class DisposableObject : IDisposableObject
+ public abstract class DisposableObject : INotifyWhenDisposed, IDisposableObject
{
+ ///
+ /// Finalizes an instance of the class.
+ ///
+ ~DisposableObject()
+ {
+ this.Dispose(false);
+ }
+
+ ///
+ /// Occurs when the object is disposed.
+ ///
+ public event EventHandler Disposed;
+
///
/// Gets a value indicating whether this instance is disposed.
///
@@ -28,34 +53,25 @@ public abstract class DisposableObject : IDisposableObject
///
public void Dispose()
{
-#if PCL
- throw new NotImplementedException();
-#else
- Dispose(true);
-#endif
+ this.Dispose(true);
}
///
/// Releases resources held by the object.
///
+ /// True if called manually, otherwise by GC.
public virtual void Dispose(bool disposing)
{
lock (this)
{
- if (disposing && !IsDisposed)
+ if (disposing && !this.IsDisposed)
{
- IsDisposed = true;
+ this.IsDisposed = true;
+ this.Disposed?.Invoke(this, EventArgs.Empty);
+ this.Disposed = null;
GC.SuppressFinalize(this);
}
}
}
-
- ///
- /// Releases resources before the object is reclaimed by garbage collection.
- ///
- ~DisposableObject()
- {
- Dispose(false);
- }
}
}
\ No newline at end of file
diff --git a/src/Ninject/Infrastructure/Disposal/IDisposableObject.cs b/src/Ninject/Infrastructure/Disposal/IDisposableObject.cs
index 90a93d80..47115fce 100644
--- a/src/Ninject/Infrastructure/Disposal/IDisposableObject.cs
+++ b/src/Ninject/Infrastructure/Disposal/IDisposableObject.cs
@@ -1,18 +1,30 @@
-#region License
-//
-// Author: Nate Kohari
-// Copyright (c) 2007-2010, Enkari, Ltd.
-//
-// Dual-licensed under the Apache License, Version 2.0, and the Microsoft Public License (Ms-PL).
-// See the file LICENSE.txt for details.
-//
-#endregion
-#region Using Directives
-using System;
-#endregion
+//-------------------------------------------------------------------------------------------------
+//
+// Copyright (c) 2007-2010, Enkari, Ltd.
+// Copyright (c) 2010-2016, Ninject Project Contributors
+// Authors: Nate Kohari (nate@enkari.com)
+// Remo Gloor (remo.gloor@gmail.com)
+//
+// 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.
+//
+//-------------------------------------------------------------------------------------------------
namespace Ninject.Infrastructure.Disposal
{
+ using System;
+
///
/// An object that can report whether or not it is disposed.
///
diff --git a/src/Ninject/Infrastructure/Disposal/INotifyWhenDisposed.cs b/src/Ninject/Infrastructure/Disposal/INotifyWhenDisposed.cs
index 944777e5..378f6a95 100644
--- a/src/Ninject/Infrastructure/Disposal/INotifyWhenDisposed.cs
+++ b/src/Ninject/Infrastructure/Disposal/INotifyWhenDisposed.cs
@@ -1,18 +1,30 @@
-#region License
-//
-// Author: Nate Kohari
-// Copyright (c) 2007-2010, Enkari, Ltd.
-//
-// Dual-licensed under the Apache License, Version 2.0, and the Microsoft Public License (Ms-PL).
-// See the file LICENSE.txt for details.
-//
-#endregion
-#region Using Directives
-using System;
-#endregion
+//-------------------------------------------------------------------------------------------------
+//
+// Copyright (c) 2007-2010, Enkari, Ltd.
+// Copyright (c) 2010-2016, Ninject Project Contributors
+// Authors: Nate Kohari (nate@enkari.com)
+// Remo Gloor (remo.gloor@gmail.com)
+//
+// 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.
+//
+//-------------------------------------------------------------------------------------------------
namespace Ninject.Infrastructure.Disposal
{
+ using System;
+
///
/// An object that fires an event when it is disposed.
///
diff --git a/src/Ninject/Infrastructure/Ensure.cs b/src/Ninject/Infrastructure/Ensure.cs
deleted file mode 100644
index d62a267f..00000000
--- a/src/Ninject/Infrastructure/Ensure.cs
+++ /dev/null
@@ -1,28 +0,0 @@
-#region License
-//
-// Author: Nate Kohari
-// Copyright (c) 2007-2010, Enkari, Ltd.
-//
-// Dual-licensed under the Apache License, Version 2.0, and the Microsoft Public License (Ms-PL).
-// See the file LICENSE.txt for details.
-//
-#endregion
-#region Using Directives
-using System;
-#endregion
-
-namespace Ninject.Infrastructure
-{
- internal static class Ensure
- {
- public static void ArgumentNotNull(object argument, string name)
- {
- if (argument == null) throw new ArgumentNullException(name, "Cannot be null");
- }
-
- public static void ArgumentNotNullOrEmpty(string argument, string name)
- {
- if (String.IsNullOrEmpty(argument)) throw new ArgumentException("Cannot be null or empty", name);
- }
- }
-}
\ No newline at end of file
diff --git a/src/Ninject/Infrastructure/Future.cs b/src/Ninject/Infrastructure/Future.cs
deleted file mode 100644
index 7dc18c9a..00000000
--- a/src/Ninject/Infrastructure/Future.cs
+++ /dev/null
@@ -1,67 +0,0 @@
-#region License
-//
-// Author: Nate Kohari
-// Copyright (c) 2007-2010, Enkari, Ltd.
-//
-// Dual-licensed under the Apache License, Version 2.0, and the Microsoft Public License (Ms-PL).
-// See the file LICENSE.txt for details.
-//
-#endregion
-#region Using Directives
-using System;
-using Ninject.Planning.Bindings;
-#endregion
-
-namespace Ninject.Infrastructure
-{
- ///
- /// Represents a future value.
- ///
- /// The type of value.
- public class Future
- {
- private bool _hasValue;
- private T _value;
-
- ///
- /// Gets the value, resolving it if necessary.
- ///
- public T Value
- {
- get
- {
- if (!_hasValue)
- {
- _value = Callback();
- _hasValue = true;
- }
-
- return _value;
- }
- }
-
- ///
- /// Gets the callback that will be called to resolve the value.
- ///
- public Func Callback { get; private set; }
-
- ///
- /// Initializes a new instance of the Future<T> class.
- ///
- /// The callback that will be triggered to read the value.
- public Future(Func callback)
- {
- Callback = callback;
- }
-
- ///
- /// Gets the value from the future.
- ///
- /// The future.
- /// The future value.
- public static implicit operator T(Future future)
- {
- return future.Value;
- }
- }
-}
\ No newline at end of file
diff --git a/src/Ninject/Infrastructure/IHaveBindingConfiguration.cs b/src/Ninject/Infrastructure/IHaveBindingConfiguration.cs
index 77a968d5..c3a7e7c9 100644
--- a/src/Ninject/Infrastructure/IHaveBindingConfiguration.cs
+++ b/src/Ninject/Infrastructure/IHaveBindingConfiguration.cs
@@ -1,19 +1,30 @@
-#region License
-//
-// Author: Nate Kohari
-// Copyright (c) 2007-2010, Enkari, Ltd.
-//
-// Dual-licensed under the Apache License, Version 2.0, and the Microsoft Public License (Ms-PL).
-// See the file LICENSE.txt for details.
-//
-#endregion
-#region Using Directives
-using System;
-using Ninject.Planning.Bindings;
-#endregion
+//-------------------------------------------------------------------------------------------------
+//
+// Copyright (c) 2007-2010, Enkari, Ltd.
+// Copyright (c) 2010-2016, Ninject Project Contributors
+// Authors: Nate Kohari (nate@enkari.com)
+// Remo Gloor (remo.gloor@gmail.com)
+//
+// 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.
+//
+//-------------------------------------------------------------------------------------------------
namespace Ninject.Infrastructure
{
+ using Ninject.Planning.Bindings;
+
///
/// Indicates the object has a reference to a .
///
diff --git a/src/Ninject/Infrastructure/Introspection/ExceptionFormatter.cs b/src/Ninject/Infrastructure/Introspection/ExceptionFormatter.cs
index 987ef2a5..8235689c 100644
--- a/src/Ninject/Infrastructure/Introspection/ExceptionFormatter.cs
+++ b/src/Ninject/Infrastructure/Introspection/ExceptionFormatter.cs
@@ -1,10 +1,10 @@
-//-------------------------------------------------------------------------------
+//-------------------------------------------------------------------------------------------------
//
-// Copyright (c) 2007-2009, Enkari, Ltd.
-// Copyright (c) 2009-2011 Ninject Project Contributors
+// Copyright (c) 2007-2010, Enkari, Ltd.
+// Copyright (c) 2010-2016, Ninject Project Contributors
// Authors: Nate Kohari (nate@enkari.com)
// Remo Gloor (remo.gloor@gmail.com)
-//
+//
// 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
@@ -19,7 +19,7 @@
// See the License for the specific language governing permissions and
// limitations under the License.
//
-//-------------------------------------------------------------------------------
+//-------------------------------------------------------------------------------------------------
namespace Ninject.Infrastructure.Introspection
{
@@ -50,6 +50,7 @@ public static string ModulesWithNullOrEmptyNamesAreNotSupported()
///
/// Generates a message saying that modules without names are not supported.
///
+ /// The target.
/// The exception message.
public static string TargetDoesNotHaveADefaultValue(ITarget target)
{
@@ -64,7 +65,6 @@ public static string TargetDoesNotHaveADefaultValue(ITarget target)
/// The exception message.
public static string ModuleWithSameNameIsAlreadyLoaded(INinjectModule newModule, INinjectModule existingModule)
{
-
using (var sw = new StringWriter())
{
sw.WriteLine("Error loading module '{0}' of type {1}", newModule.Name, newModule.GetType().Format());
@@ -72,7 +72,7 @@ public static string ModuleWithSameNameIsAlreadyLoaded(INinjectModule newModule,
sw.WriteLine("Suggestions:");
sw.WriteLine(" 1) Ensure that you have not accidentally loaded the same module twice.");
-#if !SILVERLIGHT
+#if !NO_ASSEMBLY_SCANNING
sw.WriteLine(" 2) If you are using automatic module loading, ensure you have not manually loaded a module");
sw.WriteLine(" that may be found by the module loader.");
#endif
@@ -118,6 +118,7 @@ public static string CouldNotUniquelyResolveBinding(IRequest request, string[] f
{
sw.WriteLine(" {0}) {1}", i + 1, formattedMatchingBindings[i]);
}
+
sw.WriteLine("Activation path:");
sw.WriteLine(request.FormatActivationPath());
@@ -148,7 +149,7 @@ public static string CouldNotResolveBinding(IRequest request)
sw.WriteLine(" 2) If the binding was defined in a module, ensure that the module has been loaded into the kernel.");
sw.WriteLine(" 3) Ensure you have not accidentally created more than one kernel.");
sw.WriteLine(" 4) If you are using constructor arguments, ensure that the parameter name matches the constructors parameter name.");
-#if !SILVERLIGHT
+#if !NO_ASSEMBLY_SCANNING
sw.WriteLine(" 5) If you are using automatic module loading, ensure the search path and filters are correct.");
#endif
diff --git a/src/Ninject/Infrastructure/Introspection/FormatExtensions.cs b/src/Ninject/Infrastructure/Introspection/FormatExtensions.cs
index 178c1f4d..a3471edb 100644
--- a/src/Ninject/Infrastructure/Introspection/FormatExtensions.cs
+++ b/src/Ninject/Infrastructure/Introspection/FormatExtensions.cs
@@ -1,35 +1,56 @@
-#region License
-//
-// Author: Nate Kohari
-// Copyright (c) 2007-2010, Enkari, Ltd.
-//
-// Dual-licensed under the Apache License, Version 2.0, and the Microsoft Public License (Ms-PL).
-// See the file LICENSE.txt for details.
-//
-#endregion
-#region Using Directives
-using System;
-using System.IO;
-using System.Linq;
-using System.Reflection;
-using System.Text;
-#if WINRT
-using System.Diagnostics;
-#endif
-using Ninject.Activation;
-using Ninject.Planning.Bindings;
-using Ninject.Planning.Targets;
-#endregion
+//-------------------------------------------------------------------------------------------------
+//
+// Copyright (c) 2007-2010, Enkari, Ltd.
+// Copyright (c) 2010-2016, Ninject Project Contributors
+// Authors: Nate Kohari (nate@enkari.com)
+// Remo Gloor (remo.gloor@gmail.com)
+//
+// 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.
+//
+//-------------------------------------------------------------------------------------------------
namespace Ninject.Infrastructure.Introspection
{
+ using System;
using System.Globalization;
+ using System.IO;
+ using System.Reflection;
+ using System.Text;
+ using Ninject.Activation;
+ using Ninject.Infrastructure.Language;
+ using Ninject.Planning.Bindings;
+ using Ninject.Planning.Targets;
///
/// Provides extension methods for string formatting
///
- public static class FormatExtensionsEx
+ public static class FormatExtensions
{
+#if NO_MEMBERTYPE
+ private enum MemberTypes
+ {
+ Field,
+ Event,
+ Constructor,
+ Property,
+ Method,
+ NestedType,
+ TypeInfo
+ }
+#endif
+
///
/// Formats the activation path into a meaningful string representation.
///
@@ -39,7 +60,7 @@ public static string FormatActivationPath(this IRequest request)
{
using (var sw = new StringWriter())
{
- IRequest current = request;
+ var current = request;
while (current != null)
{
@@ -51,9 +72,8 @@ public static string FormatActivationPath(this IRequest request)
}
}
-
///
- /// Formats the given binding into a meaningful string representation.
+ /// Formats the given binding into a meaningful string representation.
///
/// The binding to be formatted.
/// The context.
@@ -63,12 +83,16 @@ public static string Format(this IBinding binding, IContext context)
using (var sw = new StringWriter())
{
if (binding.Condition != null)
+ {
sw.Write("conditional ");
+ }
if (binding.IsImplicit)
+ {
sw.Write("implicit ");
+ }
- IProvider provider = binding.GetProvider(context);
+ var provider = binding.GetProvider(context);
switch (binding.Target)
{
@@ -81,8 +105,11 @@ public static string Format(this IBinding binding, IContext context)
break;
case BindingTarget.Provider:
- sw.Write("provider binding from {0} to {1} (via {2})", binding.Service.Format(),
- provider.Type.Format(), provider.GetType().Format());
+ sw.Write(
+ "provider binding from {0} to {1} (via {2})",
+ binding.Service.Format(),
+ provider.Type.Format(),
+ provider.GetType().Format());
break;
case BindingTarget.Method:
@@ -100,6 +127,7 @@ public static string Format(this IBinding binding, IContext context)
return sw.ToString();
}
}
+
///
/// Formats the specified request into a meaningful string representation.
///
@@ -107,58 +135,21 @@ public static string Format(this IBinding binding, IContext context)
/// The request formatted as string.
public static string Format(this IRequest request)
{
-#if PCL
- throw new NotImplementedException();
-#else
using (var sw = new StringWriter())
{
if (request.Target == null)
+ {
sw.Write("Request for {0}", request.Service.Format());
+ }
else
+ {
sw.Write("Injection of dependency {0} into {1}", request.Service.Format(), request.Target.Format());
+ }
return sw.ToString();
}
-#endif
}
-#if NETSTANDARD1_3
- private static MemberTypes GetMemberType(this MemberInfo member)
- {
- if (member is FieldInfo)
- return MemberTypes.Field;
- if (member is ConstructorInfo)
- return MemberTypes.Constructor;
- if (member is PropertyInfo)
- return MemberTypes.Property;
- if (member is EventInfo)
- return MemberTypes.Event;
- if (member is MethodInfo)
- return MemberTypes.Method;
-
- /*
- var typeInfo = member as Type;
- Debug.Assert(typeInfo != null);
- if (!typeInfo.IsPublic && !typeInfo.IsNotPublic)
- return MemberTypes.NestedType;
- */
- return MemberTypes.TypeInfo;
- }
-
- private enum MemberTypes
- {
- Field,
- Event,
- Constructor,
- Property,
- Method,
- NestedType,
- TypeInfo
-
- }
-
-#endif
-
///
/// Formats the specified target into a meaningful string representation..
///
@@ -166,12 +157,9 @@ private enum MemberTypes
/// The target formatted as string.
public static string Format(this ITarget target)
{
-#if PCL
- throw new NotImplementedException();
-#else
using (var sw = new StringWriter())
{
-#if !NETSTANDARD1_3
+#if !NO_MEMBERTYPE
switch (target.Member.MemberType)
#else
switch (target.Member.GetMemberType())
@@ -193,18 +181,13 @@ public static string Format(this ITarget target)
throw new ArgumentOutOfRangeException();
}
-#if !NETSTANDARD1_3
+#if !CORE
sw.Write(" of type {0}", target.Member.ReflectedType.Format());
-#else
#endif
-
return sw.ToString();
}
-#endif
-
}
-
///
/// Formats the specified type into a meaningful string representation..
///
@@ -212,25 +195,21 @@ public static string Format(this ITarget target)
/// The type formatted as string.
public static string Format(this Type type)
{
-#if PCL
- throw new NotImplementedException();
-#else
var friendlyName = GetFriendlyName(type);
-#if !MONO || __IOS__ || ANDROID
+#if !MONO
if (friendlyName.Contains("AnonymousType"))
+ {
return "AnonymousType";
+ }
#else
-
if (friendlyName.Contains("__AnonType"))
+ {
return "AnonymousType";
+ }
#endif
-#if !NETSTANDARD1_3
- switch (friendlyName.ToLower(CultureInfo.InvariantCulture))
-#else
- switch (friendlyName.ToLower())
-#endif
+ switch (friendlyName.ToLowerInvariant())
{
case "int16": return "short";
case "int32": return "int";
@@ -250,20 +229,15 @@ public static string Format(this Type type)
case "decimal": return "decimal";
}
-#if !WINRT
var genericArguments = type.GetGenericArguments();
-#else
- var ti = type.GetTypeInfo();
- var genericArguments = ti.GenericTypeParameters.Union(ti.GenericTypeArguments).ToArray();
-#endif
if (genericArguments.Length > 0)
+ {
return FormatGenericType(friendlyName, genericArguments);
+ }
return friendlyName;
-#endif
}
-
private static string GetFriendlyName(Type type)
{
@@ -272,30 +246,29 @@ private static string GetFriendlyName(Type type)
// remove generic arguments
var firstBracket = friendlyName.IndexOf('[');
if (firstBracket > 0)
+ {
friendlyName = friendlyName.Substring(0, firstBracket);
+ }
// remove assembly info
var firstComma = friendlyName.IndexOf(',');
if (firstComma > 0)
+ {
friendlyName = friendlyName.Substring(0, firstComma);
+ }
// remove namespace
var lastPeriod = friendlyName.LastIndexOf('.');
if (lastPeriod >= 0)
+ {
friendlyName = friendlyName.Substring(lastPeriod + 1);
+ }
return friendlyName;
}
private static string FormatGenericType(string friendlyName, Type[] genericArguments)
{
- //var genericTag = "`" + genericArguments.Length;
- //var genericArgumentNames = new string[genericArguments.Length];
- //for (int i = 0; i < genericArguments.Length; i++)
- // genericArgumentNames[i] = genericArguments[i].Format();
-
- //return friendlyName.Replace(genericTag, string.Join(", ", genericArgumentNames));
-
var sb = new StringBuilder(friendlyName.Length + 10);
var genericArgumentIndex = 0;
@@ -304,8 +277,8 @@ private static string FormatGenericType(string friendlyName, Type[] genericArgum
{
if (friendlyName[index] == '`')
{
- var numArguments = friendlyName[index+1] - 48;
-
+ var numArguments = friendlyName[index + 1] - 48;
+
sb.Append(friendlyName.Substring(startIndex, index - startIndex));
AppendGenericArguments(sb, genericArguments, genericArgumentIndex, numArguments);
genericArgumentIndex += numArguments;
@@ -313,28 +286,62 @@ private static string FormatGenericType(string friendlyName, Type[] genericArgum
startIndex = index + 2;
}
}
+
if (startIndex < friendlyName.Length)
+ {
sb.Append(friendlyName.Substring(startIndex));
+ }
+
return sb.ToString();
}
private static void AppendGenericArguments(StringBuilder sb, Type[] genericArguments, int start, int count)
{
-#if PCL
- throw new NotImplementedException();
-#else
sb.Append("{");
- for(int i = 0; i < count; i++)
+ for (int i = 0; i < count; i++)
{
if (i != 0)
+ {
sb.Append(", ");
+ }
sb.Append(genericArguments[start + i].Format());
}
sb.Append("}");
-#endif
}
+
+#if NO_MEMBERTYPE
+ private static MemberTypes GetMemberType(this MemberInfo member)
+ {
+ if (member is FieldInfo)
+ {
+ return MemberTypes.Field;
+ }
+
+ if (member is ConstructorInfo)
+ {
+ return MemberTypes.Constructor;
+ }
+
+ if (member is PropertyInfo)
+ {
+ return MemberTypes.Property;
+ }
+
+ if (member is EventInfo)
+ {
+ return MemberTypes.Event;
+ }
+
+ if (member is MethodInfo)
+ {
+ return MemberTypes.Method;
+ }
+
+ return MemberTypes.TypeInfo;
+ }
+#endif
}
}
\ No newline at end of file
diff --git a/src/Ninject/Infrastructure/Language/ExtensionsForAssembly.cs b/src/Ninject/Infrastructure/Language/ExtensionsForAssembly.cs
index 81e0a84c..23417b76 100644
--- a/src/Ninject/Infrastructure/Language/ExtensionsForAssembly.cs
+++ b/src/Ninject/Infrastructure/Language/ExtensionsForAssembly.cs
@@ -1,30 +1,55 @@
-#region License
-//
-// Author: Nate Kohari
-// Copyright (c) 2007-2010, Enkari, Ltd.
-//
-// Dual-licensed under the Apache License, Version 2.0, and the Microsoft Public License (Ms-PL).
-// See the file LICENSE.txt for details.
-//
-#endregion
-#if !NO_ASSEMBLY_SCANNING
-#region Using Directives
-using System;
-using System.Collections.Generic;
-using System.Linq;
-using System.Reflection;
-using Ninject.Modules;
-#endregion
+//-------------------------------------------------------------------------------------------------
+//
+// Copyright (c) 2007-2010, Enkari, Ltd.
+// Copyright (c) 2010-2016, Ninject Project Contributors
+// Authors: Nate Kohari (nate@enkari.com)
+// Remo Gloor (remo.gloor@gmail.com)
+//
+// 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.
+//
+//-------------------------------------------------------------------------------------------------
+#if !NO_ASSEMBLY_SCANNING
namespace Ninject.Infrastructure.Language
{
+ using System;
+ using System.Collections.Generic;
+ using System.Linq;
+ using System.Reflection;
+ using Ninject.Modules;
+
+ ///
+ /// Provides extension methods for .
+ ///
internal static class ExtensionsForAssembly
{
+ ///
+ /// Determines whether the assembly has loadable .
+ ///
+ /// The .
+ /// True if there's any loadable , otherwise False.
public static bool HasNinjectModules(this Assembly assembly)
{
return assembly.ExportedTypes.Any(IsLoadableModule);
}
+ ///
+ /// Gets loadable s from the .
+ ///
+ /// The .
+ /// The loadable s
public static IEnumerable GetNinjectModules(this Assembly assembly)
{
return assembly.ExportedTypes.Where(IsLoadableModule)
diff --git a/src/Ninject/Infrastructure/Language/ExtensionsForICustomAttributeProvider.cs b/src/Ninject/Infrastructure/Language/ExtensionsForICustomAttributeProvider.cs
index 18bb94dc..24a3ba02 100644
--- a/src/Ninject/Infrastructure/Language/ExtensionsForICustomAttributeProvider.cs
+++ b/src/Ninject/Infrastructure/Language/ExtensionsForICustomAttributeProvider.cs
@@ -1,29 +1,46 @@
-#region License
-//
-// Author: Nate Kohari
-// Copyright (c) 2007-2010, Enkari, Ltd.
-//
-// Dual-licensed under the Apache License, Version 2.0, and the Microsoft Public License (Ms-PL).
-// See the file LICENSE.txt for details.
-//
-#endregion
-
-using System.Collections.Generic;
-using System.Linq;
+//-------------------------------------------------------------------------------------------------
+//
+// Copyright (c) 2007-2010, Enkari, Ltd.
+// Copyright (c) 2010-2016, Ninject Project Contributors
+// Authors: Nate Kohari (nate@enkari.com)
+// Remo Gloor (remo.gloor@gmail.com)
+//
+// 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.
+//
+//-------------------------------------------------------------------------------------------------
namespace Ninject.Infrastructure.Language
{
using System;
+ using System.Collections.Generic;
+ using System.Diagnostics.Contracts;
+ using System.Linq;
using System.Reflection;
-
-#if WINRT
- using Ninject.Planning.Targets;
-#endif
+#if !NO_CUSTOM_ATTRIBUTE_PROVIDER
+ ///
+ /// Provides extension methods for .
+ ///
internal static class ExtensionsForICustomAttributeProvider
{
-#if !NETSTANDARD1_3
-
+ ///
+ /// Determines if the has the specified attribute.
+ ///
+ /// The .
+ /// The attribute type.
+ /// True if the has the attribute, otherwise False.
public static bool HasAttribute(this ICustomAttributeProvider member, Type type)
{
var memberInfo = member as MemberInfo;
@@ -35,9 +52,13 @@ public static bool HasAttribute(this ICustomAttributeProvider member, Type type)
return member.IsDefined(type, true);
}
-
-
-
+ ///
+ /// Gets custom attributes which supports and .
+ ///
+ /// The .
+ /// The attribute type.
+ /// When true, look up the hierarchy chain for the inherited custom attribute.
+ /// The attributes.
public static IEnumerable GetCustomAttributesExtended(this ICustomAttributeProvider member, Type attributeType, bool inherit)
{
var memberInfo = member as MemberInfo;
@@ -48,10 +69,22 @@ public static IEnumerable GetCustomAttributesExtended(this ICustomAtt
return member.GetCustomAttributes(attributeType, inherit).Cast();
}
-
-#endif
- public static bool HasAttribute(object target, Type type)
+#else
+ ///
+ /// Provides extension methods for that is or .
+ ///
+ internal static class ExtensionsForICustomAttributeProvider
+ {
+ ///
+ /// Determines if the target has the specified attribute.
+ ///
+ /// The that is or .
+ /// The attribute type.
+ /// True if the target has the attribute, otherwise False.
+ public static bool HasAttribute(this object target, Type type)
{
+ Contract.Requires(target is MemberInfo || target is ParameterInfo);
+
var memberInfo = target as MemberInfo;
if (memberInfo != null)
{
@@ -61,53 +94,25 @@ public static bool HasAttribute(object target, Type type)
return ((ParameterInfo)target).IsDefined(type, true);
}
-
-
- public static IEnumerable GetCustomAttributesExtended(object target, Type attributeType, bool inherit)
+ ///
+ /// Gets custom attributes which supports and .
+ ///
+ /// The that is or .
+ /// The attribute type.
+ /// When true, look up the hierarchy chain for the inherited custom attribute.
+ /// The attributes.
+ public static IEnumerable GetCustomAttributesExtended(this object target, Type attributeType, bool inherit)
{
- var memberInfo = target as MemberInfo;
- if (memberInfo != null)
- {
- return memberInfo.GetCustomAttributesExtended(attributeType, inherit);
- }
-
- return ((ParameterInfo)target).GetCustomAttributes(attributeType, inherit)
-#if !NETSTANDARD1_3
- .Cast()
-#endif
- ;
- }
-
+ Contract.Requires(target is MemberInfo || target is ParameterInfo);
- public static bool IsDefined(object target, Type attributeType, bool inherit)
- {
var memberInfo = target as MemberInfo;
if (memberInfo != null)
{
- return memberInfo.IsDefined(attributeType, inherit);
+ return memberInfo.GetCustomAttributesExtended(attributeType, inherit);
}
- return ((ParameterInfo)target).IsDefined(attributeType, inherit);
+ return ((ParameterInfo)target).GetCustomAttributes(attributeType, inherit);
}
-
- public static IEnumerable GetCustomAttributes(object target, bool inherit)
- {
- var memberInfo = target as MemberInfo;
- if (memberInfo != null)
- {
- return memberInfo.GetCustomAttributes(inherit)
-#if !NETSTANDARD1_3
- .Cast()
-#endif
- ;
- }
-
- return ((ParameterInfo)target).GetCustomAttributes(inherit)
-#if !NETSTANDARD1_3
- .Cast()
#endif
- ;
- }
-
}
}
\ No newline at end of file
diff --git a/src/Ninject/Infrastructure/Language/ExtensionsForIEnumerable.cs b/src/Ninject/Infrastructure/Language/ExtensionsForIEnumerable.cs
index d2b95a45..3bce1350 100644
--- a/src/Ninject/Infrastructure/Language/ExtensionsForIEnumerable.cs
+++ b/src/Ninject/Infrastructure/Language/ExtensionsForIEnumerable.cs
@@ -1,39 +1,85 @@
-#region License
-//
-// Author: Nate Kohari
-// Copyright (c) 2007-2010, Enkari, Ltd.
-//
-// Dual-licensed under the Apache License, Version 2.0, and the Microsoft Public License (Ms-PL).
-// See the file LICENSE.txt for details.
-//
-#endregion
-#region Using Directives
-using System;
-using System.Collections;
-using System.Linq;
-using System.Reflection;
-#endregion
+//-------------------------------------------------------------------------------------------------
+//
+// Copyright (c) 2007-2010, Enkari, Ltd.
+// Copyright (c) 2010-2016, Ninject Project Contributors
+// Authors: Nate Kohari (nate@enkari.com)
+// Remo Gloor (remo.gloor@gmail.com)
+//
+// 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.
+//
+//-------------------------------------------------------------------------------------------------
namespace Ninject.Infrastructure.Language
{
+ using System;
+ using System.Collections;
+ using System.Linq;
+ using System.Reflection;
+
+ ///
+ /// Provides extension methods for .
+ ///
internal static class ExtensionsForIEnumerable
{
+ private static readonly MethodInfo Cast;
+ private static readonly MethodInfo ToArray;
+ private static readonly MethodInfo ToList;
+
+ static ExtensionsForIEnumerable()
+ {
+ Cast = typeof(Enumerable).GetMethod(nameof(Cast));
+ ToArray = typeof(Enumerable).GetMethod(nameof(ToArray));
+ ToList = typeof(Enumerable).GetMethod(nameof(ToList));
+ }
+
+ ///
+ /// Casts the elements of an to the specified type using reflection.
+ ///
+ /// The that contains the elements to be cast.
+ /// The type to cast the elements of source to.
+ ///
+ /// An that contains each element of the
+ /// source sequence cast to the specified type.
+ ///
public static IEnumerable CastSlow(this IEnumerable series, Type elementType)
{
- var method = typeof(Enumerable).GetTypeInfo().GetDeclaredMethod("Cast").MakeGenericMethod(elementType);
+ var method = Cast.MakeGenericMethod(elementType);
return method.Invoke(null, new[] { series }) as IEnumerable;
}
+ ///
+ /// Creates an array from an .
+ ///
+ /// An to create an array from.
+ /// The type of the elements.
+ /// An array that contains the elements from the input sequence.
public static Array ToArraySlow(this IEnumerable series, Type elementType)
{
- var method = typeof(Enumerable).GetTypeInfo().GetDeclaredMethod("ToArray").MakeGenericMethod(elementType);
-
+ var method = ToArray.MakeGenericMethod(elementType);
return method.Invoke(null, new[] { series }) as Array;
}
+ ///
+ /// Creates an from an .
+ ///
+ /// An to create an from.
+ /// The type of the elements.
+ /// An that contains the elements from the input sequence.
public static IList ToListSlow(this IEnumerable series, Type elementType)
{
- var method = typeof(Enumerable).GetTypeInfo().GetDeclaredMethod("ToList").MakeGenericMethod(elementType);
+ var method = ToList.MakeGenericMethod(elementType);
return method.Invoke(null, new[] { series }) as IList;
}
}
diff --git a/src/Ninject/Infrastructure/Language/ExtensionsForIEnumerableOfT.cs b/src/Ninject/Infrastructure/Language/ExtensionsForIEnumerableOfT.cs
index f1b6d93b..37217e66 100644
--- a/src/Ninject/Infrastructure/Language/ExtensionsForIEnumerableOfT.cs
+++ b/src/Ninject/Infrastructure/Language/ExtensionsForIEnumerableOfT.cs
@@ -1,15 +1,19 @@
//-------------------------------------------------------------------------------
+//-------------------------------------------------------------------------------------------------
//
-// Copyright (c) 2009-2014 Ninject Project Contributors
-//
+// Copyright (c) 2007-2010, Enkari, Ltd.
+// Copyright (c) 2010-2016, Ninject Project Contributors
+// Authors: Nate Kohari (nate@enkari.com)
+// Remo Gloor (remo.gloor@gmail.com)
+//
// 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 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.
@@ -25,7 +29,7 @@ namespace Ninject.Infrastructure.Language
using System.Linq;
///
- /// Provides extension methods for see IEnumerable.
+ /// Provides extension methods for .
///
public static class ExtensionsForIEnumerableOfT
{
diff --git a/src/Ninject/Infrastructure/Language/ExtensionsForMemberInfo.cs b/src/Ninject/Infrastructure/Language/ExtensionsForMemberInfo.cs
index f1f94513..9fcc3a80 100644
--- a/src/Ninject/Infrastructure/Language/ExtensionsForMemberInfo.cs
+++ b/src/Ninject/Infrastructure/Language/ExtensionsForMemberInfo.cs
@@ -1,35 +1,45 @@
-#region License
+//-------------------------------------------------------------------------------------------------
+//
+// Copyright (c) 2007-2010, Enkari, Ltd.
+// Copyright (c) 2010-2016, Ninject Project Contributors
+// Authors: Nate Kohari (nate@enkari.com)
+// Remo Gloor (remo.gloor@gmail.com)
//
-// Author: Remo Gloor (remo.gloor@bbv.ch)
-// Copyright (c) 2010, bbv Software Engineering AG.
-//
-// Dual-licensed under the Apache License, Version 2.0, and the Microsoft Public License (Ms-PL).
-// See the file LICENSE.txt for details.
-//
-#endregion
+// 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.
+//
+//-------------------------------------------------------------------------------------------------
namespace Ninject.Infrastructure.Language
{
using System;
using System.Collections.Generic;
- using System.Globalization;
using System.Linq;
using System.Reflection;
-
///
/// Extensions for MemberInfo
///
public static class ExtensionsForMemberInfo
{
-
///
/// Determines whether the specified member has attribute.
///
/// The type of the attribute.
/// The member.
///
- /// true if the specified member has attribute; otherwise, false.
+ /// true if the specified member has attribute; otherwise, false.
///
public static bool HasAttribute(this MemberInfo member)
{
@@ -42,7 +52,7 @@ public static bool HasAttribute(this MemberInfo member)
/// The member.
/// The type of the attribute.
///
- /// true if the specified member has attribute; otherwise, false.
+ /// true if the specified member has attribute; otherwise, false.
///
public static bool HasAttribute(this MemberInfo member, Type type)
{
@@ -51,7 +61,7 @@ public static bool HasAttribute(this MemberInfo member, Type type)
{
return IsDefined(propertyInfo, type, true);
}
-
+
return member.IsDefined(type, true);
}
@@ -65,22 +75,10 @@ public static PropertyInfo GetPropertyFromDeclaredType(this MemberInfo memberInf
{
return memberInfo.DeclaringType.GetRuntimeProperties().FirstOrDefault(
p => p.Name == propertyDefinition.Name &&
- !p.GetMethod.IsStatic &&
+ !p.GetMethod.IsStatic &&
p.PropertyType == propertyDefinition.PropertyType &&
- p.GetIndexParameters().SequenceEqual(propertyDefinition.GetIndexParameters(), new ParameterInfoEqualityComparer())
- );
- }
- private class ParameterInfoEqualityComparer : IEqualityComparer
- {
- public bool Equals(ParameterInfo x, ParameterInfo y)
- {
- return x.Position == y.Position && x.ParameterType == y.ParameterType;
- }
-
- public int GetHashCode(ParameterInfo obj)
- {
- return obj.Position.GetHashCode() ^ obj.ParameterType.GetHashCode();
- }
+ p.GetIndexParameters().Select(pi => pi.ParameterType).SequenceEqual(
+ propertyDefinition.GetIndexParameters().Select(pi => pi.ParameterType)));
}
///
@@ -88,7 +86,7 @@ public int GetHashCode(ParameterInfo obj)
///
/// The property info.
///
- /// true if the specified property info is private; otherwise, false.
+ /// true if the specified property info is private; otherwise, false.
///
public static bool IsPrivate(this PropertyInfo propertyInfo)
{
@@ -98,7 +96,6 @@ public static bool IsPrivate(this PropertyInfo propertyInfo)
return (getMethod == null || getMethod.IsPrivate) && (setMethod == null || setMethod.IsPrivate);
}
-
///
/// Gets the custom attributes.
/// This version is able to get custom attributes for properties from base types even if the property is non-public.
@@ -106,9 +103,12 @@ public static bool IsPrivate(this PropertyInfo propertyInfo)
/// The member.
/// Type of the attribute.
/// if set to true [inherited].
- ///
+ /// The custom attributes.
public static IEnumerable GetCustomAttributesExtended(this MemberInfo member, Type attributeType, bool inherited)
{
+#if !CORE
+ return Attribute.GetCustomAttributes(member, attributeType, inherited);
+#else
var propertyInfo = member as PropertyInfo;
if (propertyInfo != null)
{
@@ -116,9 +116,9 @@ public static IEnumerable GetCustomAttributesExtended(this MemberInfo
}
return member.GetCustomAttributes(attributeType, inherited).Cast();
+#endif
}
-
private static PropertyInfo GetParentDefinition(PropertyInfo property)
{
var propertyMethod = property.GetMethod ?? property.SetMethod;
@@ -144,15 +144,13 @@ private static MethodInfo GetParentDefinition(this MethodInfo method)
MethodInfo result = null;
while (result == null && type != null)
{
-
result = type.GetRuntimeMethods().SingleOrDefault(m => !m.IsStatic && m.GetRuntimeBaseDefinition().Equals(baseDefinition));
type = type.GetTypeInfo().BaseType;
-
}
return result;
}
-
+
private static bool IsDefined(PropertyInfo element, Type attributeType, bool inherit)
{
if (element.IsDefined(attributeType, false))
@@ -206,12 +204,11 @@ private static IEnumerable GetCustomAttributes(PropertyInfo propertyI
return propertyInfo.GetCustomAttributes(attributeType, inherit).Cast();
}
-
private static void AddAttributes(List attributes, IEnumerable customAttributes, Dictionary attributeUsages)
{
foreach (var attribute in customAttributes)
{
- Type type = attribute.GetType();
+ var type = attribute.GetType();
if (!attributeUsages.ContainsKey(type))
{
attributeUsages[type] = InternalGetAttributeUsage(type).Inherited;
@@ -226,8 +223,7 @@ private static void AddAttributes(List attributes, IEnumerable(true);
+ }
}
}
\ No newline at end of file
diff --git a/src/Ninject/Infrastructure/Language/ExtensionsForTargetInvocationException.cs b/src/Ninject/Infrastructure/Language/ExtensionsForTargetInvocationException.cs
index 531ced09..041cd3a5 100644
--- a/src/Ninject/Infrastructure/Language/ExtensionsForTargetInvocationException.cs
+++ b/src/Ninject/Infrastructure/Language/ExtensionsForTargetInvocationException.cs
@@ -1,25 +1,44 @@
-#region License
-//
-// Author: Nate Kohari
-// Copyright (c) 2007-2010, Enkari, Ltd.
-//
-// Dual-licensed under the Apache License, Version 2.0, and the Microsoft Public License (Ms-PL).
-// See the file LICENSE.txt for details.
-//
-#endregion
-#region Using Directives
-using System;
-using System.Reflection;
-using System.Runtime.ExceptionServices;
-#endregion
+//-------------------------------------------------------------------------------------------------
+//
+// Copyright (c) 2007-2010, Enkari, Ltd.
+// Copyright (c) 2010-2016, Ninject Project Contributors
+// Authors: Nate Kohari (nate@enkari.com)
+// Remo Gloor (remo.gloor@gmail.com)
+//
+// 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.
+//
+//-------------------------------------------------------------------------------------------------
namespace Ninject.Infrastructure.Language
{
+ using System;
+ using System.Reflection;
+ using System.Runtime.ExceptionServices;
+
+ ///
+ /// Provides extension methods for .
+ ///
internal static class ExtensionsForTargetInvocationException
{
+ ///
+ /// Re-throws inner exception.
+ ///
+ /// The .
public static void RethrowInnerException(this TargetInvocationException exception)
{
- Exception innerException = exception.InnerException;
+ var innerException = exception.InnerException;
ExceptionDispatchInfo.Capture(innerException).Throw();
throw innerException;
diff --git a/src/Ninject/Infrastructure/Language/ExtensionsForType.cs b/src/Ninject/Infrastructure/Language/ExtensionsForType.cs
index 7778b2f5..578cb4db 100644
--- a/src/Ninject/Infrastructure/Language/ExtensionsForType.cs
+++ b/src/Ninject/Infrastructure/Language/ExtensionsForType.cs
@@ -1,8 +1,11 @@
//-------------------------------------------------------------------------------
+//-------------------------------------------------------------------------------------------------
//
-// Copyright (c) 2009-2011 Ninject Project Contributors
-// Authors: Remo Gloor (remo.gloor@gmail.com)
-//
+// Copyright (c) 2007-2010, Enkari, Ltd.
+// Copyright (c) 2010-2016, Ninject Project Contributors
+// Authors: Nate Kohari (nate@enkari.com)
+// Remo Gloor (remo.gloor@gmail.com)
+//
// 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
@@ -19,17 +22,15 @@
//
//-------------------------------------------------------------------------------
-using System.Reflection;
-
namespace Ninject.Infrastructure.Language
{
using System;
using System.Collections.Generic;
+ using System.Reflection;
///
- /// Extension methods for type
+ /// Extension methods for .
///
- ///
public static class ExtensionsForType
{
///
diff --git a/src/Ninject/Infrastructure/Multimap.cs b/src/Ninject/Infrastructure/Multimap.cs
index e03c8f49..117cbf68 100644
--- a/src/Ninject/Infrastructure/Multimap.cs
+++ b/src/Ninject/Infrastructure/Multimap.cs
@@ -1,20 +1,29 @@
-#region License
-//
-// Author: Nate Kohari
-// Copyright (c) 2007-2010, Enkari, Ltd.
-//
-// Dual-licensed under the Apache License, Version 2.0, and the Microsoft Public License (Ms-PL).
-// See the file LICENSE.txt for details.
-//
-#endregion
-#region Using Directives
-using System;
-using System.Collections;
-using System.Collections.Generic;
-#endregion
+//-------------------------------------------------------------------------------------------------
+//
+// Copyright (c) 2007-2010, Enkari, Ltd.
+// Copyright (c) 2010-2016, Ninject Project Contributors
+// Authors: Nate Kohari (nate@enkari.com)
+// Remo Gloor (remo.gloor@gmail.com)
+//
+// 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.
+//
+//-------------------------------------------------------------------------------------------------
namespace Ninject.Infrastructure
{
+ using System.Collections.Generic;
using System.Linq;
///
@@ -22,24 +31,10 @@ namespace Ninject.Infrastructure
///
/// The type of key.
/// The type of value.
- public class Multimap //: IEnumerable>>
+ public class Multimap // : IEnumerable>>
{
private readonly Dictionary> items = new Dictionary>();
- ///
- /// Gets the collection of values stored under the specified key.
- ///
- /// The key.
- public IEnumerable this[K key]
- {
- get
- {
- ICollection result;
-
- return this.items.TryGetValue(key, out result) ? result : Enumerable.Empty();
- }
- }
-
///
/// Gets the collection of keys.
///
@@ -56,6 +51,20 @@ public ICollection> Values
get { return this.items.Values; }
}
+ ///
+ /// Gets the collection of values stored under the specified key.
+ ///
+ /// The key.
+ public IEnumerable this[K key]
+ {
+ get
+ {
+ ICollection result;
+
+ return this.items.TryGetValue(key, out result) ? result : Enumerable.Empty();
+ }
+ }
+
///
/// Adds the specified value for the specified key.
///
@@ -76,7 +85,7 @@ public bool Remove(K key, V value)
{
ICollection values;
- return this.items.TryGetValue(key, out values) &&
+ return this.items.TryGetValue(key, out values) &&
values.Remove(value);
}
@@ -107,6 +116,7 @@ public bool ContainsKey(K key)
{
return this.items.ContainsKey(key);
}
+
/*
///
/// Returns an enumerator that iterates through a the multimap.
diff --git a/src/Ninject/Infrastructure/ReferenceEqualWeakReference.cs b/src/Ninject/Infrastructure/ReferenceEqualWeakReference.cs
index d0f2cfca..40e948f1 100644
--- a/src/Ninject/Infrastructure/ReferenceEqualWeakReference.cs
+++ b/src/Ninject/Infrastructure/ReferenceEqualWeakReference.cs
@@ -1,19 +1,30 @@
-#region License
-//
-// Author: Remo Gloor (remo.gloor@bbv.ch)
-// Copyright (c) 2010, bbv Software Services AG
-//
-// Dual-licensed under the Apache License, Version 2.0, and the Microsoft Public License (Ms-PL).
-// See the file LICENSE.txt for details.
-//
-#endregion
+//-------------------------------------------------------------------------------------------------
+//
+// Copyright (c) 2007-2010, Enkari, Ltd.
+// Copyright (c) 2010-2016, Ninject Project Contributors
+// Authors: Nate Kohari (nate@enkari.com)
+// Remo Gloor (remo.gloor@gmail.com)
+//
+// 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.
+//
+//-------------------------------------------------------------------------------------------------
+
namespace Ninject.Infrastructure
{
using System;
using System.Runtime.CompilerServices;
-#if SILVERLIGHT
- using WeakReference = BaseWeakReference;
-#endif
///
/// Weak reference that can be used in collections. It is equal to the
@@ -27,9 +38,9 @@ public class ReferenceEqualWeakReference : WeakReference
/// Initializes a new instance of the class.
///
/// The target.
- public ReferenceEqualWeakReference(object target) : base(target)
+ public ReferenceEqualWeakReference(object target)
+ : base(target)
{
-
this.cashedHashCode = RuntimeHelpers.GetHashCode(target);
}
@@ -38,7 +49,8 @@ public ReferenceEqualWeakReference(object target) : base(target)
///
/// The target.
/// if set to true [track resurrection].
- public ReferenceEqualWeakReference(object target, bool trackResurrection) : base(target, trackResurrection)
+ public ReferenceEqualWeakReference(object target, bool trackResurrection)
+ : base(target, trackResurrection)
{
this.cashedHashCode = RuntimeHelpers.GetHashCode(target);
}
@@ -70,7 +82,7 @@ public override bool Equals(object obj)
/// Returns a hash code for this instance.
///
///
- /// A hash code for this instance, suitable for use in hashing algorithms and data structures like a hash table.
+ /// A hash code for this instance, suitable for use in hashing algorithms and data structures like a hash table.
///
public override int GetHashCode()
{
diff --git a/src/Ninject/Infrastructure/StandardScopeCallbacks.cs b/src/Ninject/Infrastructure/StandardScopeCallbacks.cs
index cca41b31..5f636e87 100644
--- a/src/Ninject/Infrastructure/StandardScopeCallbacks.cs
+++ b/src/Ninject/Infrastructure/StandardScopeCallbacks.cs
@@ -1,19 +1,31 @@
-#region License
-//
-// Author: Nate Kohari
-// Copyright (c) 2007-2010, Enkari, Ltd.
-//
-// Dual-licensed under the Apache License, Version 2.0, and the Microsoft Public License (Ms-PL).
-// See the file LICENSE.txt for details.
-//
-#endregion
-#region Using Directives
-using System;
-using Ninject.Activation;
-#endregion
+//-------------------------------------------------------------------------------------------------
+//
+// Copyright (c) 2007-2010, Enkari, Ltd.
+// Copyright (c) 2010-2016, Ninject Project Contributors
+// Authors: Nate Kohari (nate@enkari.com)
+// Remo Gloor (remo.gloor@gmail.com)
+//
+// 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.
+//
+//-------------------------------------------------------------------------------------------------
namespace Ninject.Infrastructure
{
+ using System;
+ using Ninject.Activation;
+
///
/// Scope callbacks for standard scopes.
///
@@ -29,7 +41,7 @@ public class StandardScopeCallbacks
///
public static readonly Func Singleton = ctx => ctx.Kernel;
-#if !NETSTANDARD1_3 && !WINRT
+#if !CORE
///
/// Gets the callback for thread scope.
///
diff --git a/src/Ninject/Infrastructure/Threading/ReaderWriterLock.cs b/src/Ninject/Infrastructure/Threading/ReaderWriterLock.cs
deleted file mode 100644
index 83263d7b..00000000
--- a/src/Ninject/Infrastructure/Threading/ReaderWriterLock.cs
+++ /dev/null
@@ -1,405 +0,0 @@
-// --------------------------------------------------------------------------------------------------------------------
-//
-//
-//
-//
-// A reader-writer lock implementation that is intended to be simple, yet very
-// efficient. In particular only 1 interlocked operation is taken for any lock
-// operation (we use spin locks to achieve this). The spin lock is never held
-// for more than a few instructions (in particular, we never call event APIs
-// or in fact any non-trivial API while holding the spin lock).
-// Currently this ReaderWriterLock does not support recursion, however it is
-// not hard to add
-//
-// --------------------------------------------------------------------------------------------------------------------
-
-#if SILVERLIGHT
-namespace System.Threading
-{
- using System.Diagnostics;
-
- ///
- /// A reader-writer lock implementation that is intended to be simple, yet very
- /// efficient. In particular only 1 interlocked operation is taken for any lock
- /// operation (we use spin locks to achieve this). The spin lock is never held
- /// for more than a few instructions (in particular, we never call event APIs
- /// or in fact any non-trivial API while holding the spin lock).
- ///
- /// Currently this ReaderWriterLock does not support recursion, however it is
- /// not hard to add
- ///
- ///
- /// By Vance Morrison
- /// Taken from - http://blogs.msdn.com/vancem/archive/2006/03/28/563180.aspx
- /// Code at - http://blogs.msdn.com/vancem/attachment/563180.ashx
- ///
- public class ReaderWriterLock
- {
- // Lock specification for myLock: This lock protects exactly the local fields associated
- // instance of MyReaderWriterLock. It does NOT protect the memory associated with the
- // the events that hang off this lock (eg writeEvent, readEvent upgradeEvent).
-#region Constants and Fields
-
- ///
- /// The my lock.
- ///
- private int myLock;
-
- // Who owns the lock owners > 0 => readers
- // owners = -1 means there is one writer. Owners must be >= -1.
-
- ///
- /// The number read waiters.
- ///
- private uint numReadWaiters; // maximum number of threads that can be doing a WaitOne on the readEvent
-
- ///
- /// The number upgrade waiters.
- ///
- private uint numUpgradeWaiters; // maximum number of threads that can be doing a WaitOne on the upgradeEvent (at most 1).
-
- ///
- /// The number write waiters.
- ///
- private uint numWriteWaiters; // maximum number of threads that can be doing a WaitOne on the writeEvent
-
- ///
- /// The owners.
- ///
- private int owners;
-
- // conditions we wait on.
-
- ///
- /// The read event.
- ///
- private EventWaitHandle readEvent; // threads waiting to acquire a read lock go here (will be released in bulk)
-
- ///
- /// The upgrade event.
- ///
- private EventWaitHandle upgradeEvent; // thread waiting to upgrade a read lock to a write lock go here (at most one)
-
- ///
- /// The write event.
- ///
- private EventWaitHandle writeEvent; // threads waiting to acquire a write lock go here.
-
-#endregion
-
-#region Properties
-
- ///
- /// Gets a value indicating whether MyLockHeld.
- ///
- private bool MyLockHeld
- {
- get
- {
- return this.myLock != 0;
- }
- }
-
-#endregion
-
-#region Public Methods
-
- ///
- /// The acquire reader lock.
- ///
- ///
- /// The milliseconds timeout.
- ///
- public void AcquireReaderLock(int millisecondsTimeout)
- {
- this.EnterMyLock();
- for (;;)
- {
- // We can enter a read lock if there are only read-locks have been given out
- // and a writer is not trying to get in.
- if (this.owners >= 0 && this.numWriteWaiters == 0)
- {
- // Good case, there is no contention, we are basically done
- this.owners++; // Indicate we have another reader
- break;
- }
-
- // Drat, we need to wait. Mark that we have waiters and wait.
- if (this.readEvent == null)
- {
- // Create the needed event
- this.LazyCreateEvent(ref this.readEvent, false);
- continue; // since we left the lock, start over.
- }
-
- this.WaitOnEvent(this.readEvent, ref this.numReadWaiters, millisecondsTimeout);
- }
-
- this.ExitMyLock();
- }
-
- ///
- /// The acquire writer lock.
- ///
- ///
- /// The milliseconds timeout.
- ///
- public void AcquireWriterLock(int millisecondsTimeout)
- {
- this.EnterMyLock();
- for (;;)
- {
- if (this.owners == 0)
- {
- // Good case, there is no contention, we are basically done
- this.owners = -1; // indicate we have a writer.
- break;
- }
-
- // Drat, we need to wait. Mark that we have waiters and wait.
- if (this.writeEvent == null)
- {
- // create the needed event.
- this.LazyCreateEvent(ref this.writeEvent, true);
- continue; // since we left the lock, start over.
- }
-
- this.WaitOnEvent(this.writeEvent, ref this.numWriteWaiters, millisecondsTimeout);
- }
-
- this.ExitMyLock();
- }
-
- ///
- /// The downgrade to reader lock.
- ///
- /// The lock cookie.
- public void DowngradeFromWriterLock(ref int lockCookie)
- {
- this.EnterMyLock();
- Debug.Assert(this.owners == -1, "Downgrading when no writer lock held");
- this.owners = 1;
- this.ExitAndWakeUpAppropriateWaiters();
- }
-
- ///
- /// The release reader lock.
- ///
- public void ReleaseReaderLock()
- {
- this.EnterMyLock();
- Debug.Assert(this.owners > 0, "ReleasingReaderLock: releasing lock and no read lock taken");
- --this.owners;
- this.ExitAndWakeUpAppropriateWaiters();
- }
-
- ///
- /// The release writer lock.
- ///
- public void ReleaseWriterLock()
- {
- this.EnterMyLock();
- Debug.Assert(this.owners == -1, "Calling ReleaseWriterLock when no write lock is held");
- Debug.Assert(this.numUpgradeWaiters > 0);
- this.owners++;
- this.ExitAndWakeUpAppropriateWaiters();
- }
-
- ///
- /// The upgrade to writer lock.
- ///
- ///
- /// The milliseconds timeout.
- ///
- ///
- ///
- public int UpgradeToWriterLock(int millisecondsTimeout)
- {
- this.EnterMyLock();
- for (;;)
- {
- Debug.Assert(this.owners > 0, "Upgrading when no reader lock held");
- if (this.owners == 1)
- {
- // Good case, there is no contention, we are basically done
- this.owners = -1; // indicate we have a writer.
- break;
- }
-
- // Drat, we need to wait. Mark that we have waiters and wait.
- if (this.upgradeEvent == null)
- {
- // Create the needed event
- this.LazyCreateEvent(ref this.upgradeEvent, false);
- continue; // since we left the lock, start over.
- }
-
- if (this.numUpgradeWaiters > 0)
- {
- this.ExitMyLock();
- throw new InvalidOperationException("UpgradeToWriterLock already in process. Deadlock!");
- }
-
- this.WaitOnEvent(this.upgradeEvent, ref this.numUpgradeWaiters, millisecondsTimeout);
- }
-
- this.ExitMyLock();
- return 0;
- }
-
-#endregion
-
-#region Methods
-
- ///
- /// The enter my lock.
- ///
- private void EnterMyLock()
- {
- if (Interlocked.CompareExchange(ref this.myLock, 1, 0) != 0)
- {
- this.EnterMyLockSpin();
- }
- }
-
- ///
- /// The enter my lock spin.
- ///
- private void EnterMyLockSpin()
- {
- for (int i = 0;; i++)
- {
- if (i < 3 && Environment.ProcessorCount > 1)
- {
- Thread.SpinWait(20); // Wait a few dozen instructions to let another processor release lock.
- }
- else
- {
- Thread.Sleep(0); // Give up my quantum.
- }
-
- if (Interlocked.CompareExchange(ref this.myLock, 1, 0) == 0)
- {
- return;
- }
- }
- }
-
- ///
- /// Determines the appropriate events to set, leaves the locks, and sets the events.
- ///
- private void ExitAndWakeUpAppropriateWaiters()
- {
- Debug.Assert(this.MyLockHeld);
-
- if (this.owners == 0 && this.numWriteWaiters > 0)
- {
- this.ExitMyLock(); // Exit before signaling to improve efficiency (wakee will need the lock)
- this.writeEvent.Set(); // release one writer.
- }
- else if (this.owners == 1 && this.numUpgradeWaiters != 0)
- {
- this.ExitMyLock(); // Exit before signaling to improve efficiency (wakee will need the lock)
- this.upgradeEvent.Set(); // release all upgraders (however there can be at most one).
-
- // two threads upgrading is a guaranteed deadlock, so we throw in that case.
- }
- else if (this.owners >= 0 && this.numReadWaiters != 0)
- {
- this.ExitMyLock(); // Exit before signaling to improve efficiency (wakee will need the lock)
- this.readEvent.Set(); // release all readers.
- }
- else
- {
- this.ExitMyLock();
- }
- }
-
- ///
- /// The exit my lock.
- ///
- private void ExitMyLock()
- {
- Debug.Assert(this.myLock != 0, "Exiting spin lock that is not held");
- this.myLock = 0;
- }
-
- ///
- /// A routine for lazily creating a event outside the lock (so if errors
- /// happen they are outside the lock and that we don't do much work
- /// while holding a spin lock). If all goes well, reenter the lock and
- /// set 'waitEvent'
- ///
- ///
- /// The wait Event.
- ///
- ///
- /// The make Auto Reset Event.
- ///
- private void LazyCreateEvent(ref EventWaitHandle waitEvent, bool makeAutoResetEvent)
- {
- Debug.Assert(this.MyLockHeld);
- Debug.Assert(waitEvent == null);
-
- this.ExitMyLock();
- EventWaitHandle newEvent;
- if (makeAutoResetEvent)
- {
- newEvent = new AutoResetEvent(false);
- }
- else
- {
- newEvent = new ManualResetEvent(false);
- }
-
- this.EnterMyLock();
- waitEvent = newEvent;
- }
-
- ///
- /// Waits on 'waitEvent' with a timeout of 'millisecondsTimeout.
- /// Before the wait 'numWaiters' is incremented and is restored before leaving this routine.
- ///
- ///
- /// The wait Event.
- ///
- ///
- /// The num Waiters.
- ///
- ///
- /// The milliseconds Timeout.
- ///
- private void WaitOnEvent(EventWaitHandle waitEvent, ref uint numWaiters, int millisecondsTimeout)
- {
- Debug.Assert(this.MyLockHeld);
-
- waitEvent.Reset();
- numWaiters++;
-
- bool waitSuccessful = false;
- this.ExitMyLock(); // Do the wait outside of any lock
- try
- {
- if (!waitEvent.WaitOne(millisecondsTimeout))
- {
- throw new InvalidOperationException("ReaderWriterLock timeout expired");
- }
-
- waitSuccessful = true;
- }
- finally
- {
- this.EnterMyLock();
- --numWaiters;
- if (!waitSuccessful)
- {
- // We are going to throw for some reason. Exit myLock.
- this.ExitMyLock();
- }
- }
- }
-
-#endregion
- }
-}
-#endif
\ No newline at end of file
diff --git a/src/Ninject/Injection/ConstructorInjector.cs b/src/Ninject/Injection/ConstructorInjector.cs
index 83fedbab..66769bbd 100644
--- a/src/Ninject/Injection/ConstructorInjector.cs
+++ b/src/Ninject/Injection/ConstructorInjector.cs
@@ -1,17 +1,32 @@
-#region License
-//
-// Author: Nate Kohari
-// Copyright (c) 2007-2010, Enkari, Ltd.
-//
-// Dual-licensed under the Apache License, Version 2.0, and the Microsoft Public License (Ms-PL).
-// See the file LICENSE.txt for details.
-//
-#endregion
+//-------------------------------------------------------------------------------------------------
+//
+// Copyright (c) 2007-2010, Enkari, Ltd.
+// Copyright (c) 2010-2016, Ninject Project Contributors
+// Authors: Nate Kohari (nate@enkari.com)
+// Remo Gloor (remo.gloor@gmail.com)
+//
+// 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.
+//
+//-------------------------------------------------------------------------------------------------
namespace Ninject.Injection
{
///
- /// A delegate that can inject values into a constructor.
+ /// Represents a delegate that can inject values into a constructor.
///
+ /// The arguments used for the constructor.
+ /// An object created from the constructor.
public delegate object ConstructorInjector(params object[] arguments);
}
\ No newline at end of file
diff --git a/src/Ninject/Injection/DynamicMethodInjectorFactory.cs b/src/Ninject/Injection/DynamicMethodInjectorFactory.cs
index 9ab5931b..97eb7cf7 100644
--- a/src/Ninject/Injection/DynamicMethodInjectorFactory.cs
+++ b/src/Ninject/Injection/DynamicMethodInjectorFactory.cs
@@ -1,24 +1,34 @@
-#region License
-//
-// Author: Nate Kohari
-// Copyright (c) 2007-2010, Enkari, Ltd.
-//
-// Dual-licensed under the Apache License, Version 2.0, and the Microsoft Public License (Ms-PL).
-// See the file LICENSE.txt for details.
-//
-#endregion
-#if !NO_LCG
-#region Using Directives
-using System;
-using System.Reflection;
-#if !PCL
-using System.Reflection.Emit;
-#endif
-using Ninject.Components;
-#endregion
+//-------------------------------------------------------------------------------------------------
+//
+// Copyright (c) 2007-2010, Enkari, Ltd.
+// Copyright (c) 2010-2016, Ninject Project Contributors
+// Authors: Nate Kohari (nate@enkari.com)
+// Remo Gloor (remo.gloor@gmail.com)
+//
+// 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.
+//
+//-------------------------------------------------------------------------------------------------
+#if !NO_LCG
namespace Ninject.Injection
{
+ using System;
+ using System.Reflection;
+ using System.Reflection.Emit;
+ using Ninject.Components;
+
///
/// Creates injectors for members via DynamicMethods.
///
@@ -31,31 +41,21 @@ public class DynamicMethodInjectorFactory : NinjectComponent, IInjectorFactory
/// The created injector.
public ConstructorInjector Create(ConstructorInfo constructor)
{
-#if PCL
- throw new NotImplementedException();
-#else
- #if SILVERLIGHT
- var dynamicMethod = new DynamicMethod(GetAnonymousMethodName(), typeof(object), new[] { typeof(object[]) });
- #else
var dynamicMethod = new DynamicMethod(GetAnonymousMethodName(), typeof(object), new[] { typeof(object[]) }, true);
- #endif
- ILGenerator il = dynamicMethod.GetILGenerator();
+ var il = dynamicMethod.GetILGenerator();
EmitLoadMethodArguments(il, constructor);
il.Emit(OpCodes.Newobj, constructor);
-#if !WINRT
- if (constructor.ReflectedType.IsValueType)
- il.Emit(OpCodes.Box, constructor.ReflectedType);
-#else
if (constructor.DeclaringType.GetTypeInfo().IsValueType)
+ {
il.Emit(OpCodes.Box, constructor.DeclaringType);
-#endif
+ }
+
il.Emit(OpCodes.Ret);
- return (ConstructorInjector) dynamicMethod.CreateDelegate(typeof(ConstructorInjector));
-#endif
+ return (ConstructorInjector)dynamicMethod.CreateDelegate(typeof(ConstructorInjector));
}
///
@@ -65,16 +65,13 @@ public ConstructorInjector Create(ConstructorInfo constructor)
/// The created injector.
public PropertyInjector Create(PropertyInfo property)
{
-#if PCL
- throw new NotImplementedException();
-#else
- #if NO_SKIP_VISIBILITY
+#if NO_SKIP_VISIBILITY
var dynamicMethod = new DynamicMethod(GetAnonymousMethodName(), typeof(void), new[] { typeof(object), typeof(object) });
- #else
+#else
var dynamicMethod = new DynamicMethod(GetAnonymousMethodName(), typeof(void), new[] { typeof(object), typeof(object) }, true);
- #endif
-
- ILGenerator il = dynamicMethod.GetILGenerator();
+#endif
+
+ var il = dynamicMethod.GetILGenerator();
il.Emit(OpCodes.Ldarg_0);
EmitUnboxOrCast(il, property.DeclaringType);
@@ -82,23 +79,12 @@ public PropertyInjector Create(PropertyInfo property)
il.Emit(OpCodes.Ldarg_1);
EmitUnboxOrCast(il, property.PropertyType);
- #if !SILVERLIGHT
- bool injectNonPublic = Settings.InjectNonPublic;
- #else
- const bool injectNonPublic = false;
- #endif // !SILVERLIGHT
+ var injectNonPublic = this.Settings.InjectNonPublic;
- EmitMethodCall(il,
-#if !WINRT
- property.GetSetMethod(injectNonPublic)
-#else
- property.SetMethod
-#endif
- );
+ EmitMethodCall(il, property.GetSetMethod(injectNonPublic));
il.Emit(OpCodes.Ret);
- return (PropertyInjector) dynamicMethod.CreateDelegate(typeof(PropertyInjector));
-#endif
+ return (PropertyInjector)dynamicMethod.CreateDelegate(typeof(PropertyInjector));
}
///
@@ -108,16 +94,13 @@ public PropertyInjector Create(PropertyInfo property)
/// The created injector.
public MethodInjector Create(MethodInfo method)
{
-#if PCL
- throw new NotImplementedException();
-#else
- #if NO_SKIP_VISIBILITY
+#if NO_SKIP_VISIBILITY
var dynamicMethod = new DynamicMethod(GetAnonymousMethodName(), typeof(void), new[] { typeof(object), typeof(object[]) });
- #else
+#else
var dynamicMethod = new DynamicMethod(GetAnonymousMethodName(), typeof(void), new[] { typeof(object), typeof(object[]) }, true);
- #endif
+#endif
- ILGenerator il = dynamicMethod.GetILGenerator();
+ var il = dynamicMethod.GetILGenerator();
il.Emit(OpCodes.Ldarg_0);
EmitUnboxOrCast(il, method.DeclaringType);
@@ -126,20 +109,20 @@ public MethodInjector Create(MethodInfo method)
EmitMethodCall(il, method);
if (method.ReturnType != typeof(void))
+ {
il.Emit(OpCodes.Pop);
+ }
il.Emit(OpCodes.Ret);
- return (MethodInjector) dynamicMethod.CreateDelegate(typeof(MethodInjector));
-#endif
+ return (MethodInjector)dynamicMethod.CreateDelegate(typeof(MethodInjector));
}
-#if !NETSTANDARD1_3
private static void EmitLoadMethodArguments(ILGenerator il, MethodBase targetMethod)
{
- ParameterInfo[] parameters = targetMethod.GetParameters();
- OpCode ldargOpcode = targetMethod is ConstructorInfo ? OpCodes.Ldarg_0 : OpCodes.Ldarg_1;
-
+ var parameters = targetMethod.GetParameters();
+ var ldargOpcode = targetMethod is ConstructorInfo ? OpCodes.Ldarg_0 : OpCodes.Ldarg_1;
+
for (int idx = 0; idx < parameters.Length; idx++)
{
il.Emit(ldargOpcode);
@@ -152,17 +135,13 @@ private static void EmitLoadMethodArguments(ILGenerator il, MethodBase targetMet
private static void EmitMethodCall(ILGenerator il, MethodInfo method)
{
- OpCode opCode = method.IsFinal ? OpCodes.Call : OpCodes.Callvirt;
+ var opCode = method.IsFinal ? OpCodes.Call : OpCodes.Callvirt;
il.Emit(opCode, method);
}
private static void EmitUnboxOrCast(ILGenerator il, Type type)
{
- OpCode opCode = type
-#if WINRT
- .GetTypeInfo()
-#endif
- .IsValueType ? OpCodes.Unbox_Any : OpCodes.Castclass;
+ var opCode = type.GetTypeInfo().IsValueType ? OpCodes.Unbox_Any : OpCodes.Castclass;
il.Emit(opCode, type);
}
@@ -170,7 +149,6 @@ private static string GetAnonymousMethodName()
{
return "DynamicInjector" + Guid.NewGuid().ToString("N");
}
-#endif
}
}
#endif //!NO_LCG
\ No newline at end of file
diff --git a/src/Ninject/Injection/IInjectorFactory.cs b/src/Ninject/Injection/IInjectorFactory.cs
index 073b6562..c1c8268c 100644
--- a/src/Ninject/Injection/IInjectorFactory.cs
+++ b/src/Ninject/Injection/IInjectorFactory.cs
@@ -1,20 +1,31 @@
-#region License
-//
-// Author: Nate Kohari
-// Copyright (c) 2007-2010, Enkari, Ltd.
-//
-// Dual-licensed under the Apache License, Version 2.0, and the Microsoft Public License (Ms-PL).
-// See the file LICENSE.txt for details.
-//
-#endregion
-#region Using Directives
-using System;
-using System.Reflection;
-using Ninject.Components;
-#endregion
+//-------------------------------------------------------------------------------------------------
+//
+// Copyright (c) 2007-2010, Enkari, Ltd.
+// Copyright (c) 2010-2016, Ninject Project Contributors
+// Authors: Nate Kohari (nate@enkari.com)
+// Remo Gloor (remo.gloor@gmail.com)
+//
+// 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.
+//
+//-------------------------------------------------------------------------------------------------
namespace Ninject.Injection
{
+ using System.Reflection;
+ using Ninject.Components;
+
///
/// Creates injectors from members.
///
diff --git a/src/Ninject/Injection/MethodInjector.cs b/src/Ninject/Injection/MethodInjector.cs
index abf02a86..7c6d7eb8 100644
--- a/src/Ninject/Injection/MethodInjector.cs
+++ b/src/Ninject/Injection/MethodInjector.cs
@@ -1,16 +1,32 @@
-#region License
-//
-// Author: Nate Kohari
-// Copyright (c) 2007-2010, Enkari, Ltd.
-//
-// Dual-licensed under the Apache License, Version 2.0, and the Microsoft Public License (Ms-PL).
-// See the file LICENSE.txt for details.
-//
-#endregion
+//-------------------------------------------------------------------------------------------------
+//
+// Copyright (c) 2007-2010, Enkari, Ltd.
+// Copyright (c) 2010-2016, Ninject Project Contributors
+// Authors: Nate Kohari (nate@enkari.com)
+// Remo Gloor (remo.gloor@gmail.com)
+//
+// 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.
+//
+//-------------------------------------------------------------------------------------------------
+
namespace Ninject.Injection
{
///
- /// A delegate that can inject values into a method.
+ /// Represents a delegate that can inject values into a method.
///
+ /// The method info.
+ /// The arguments used for the method.
public delegate void MethodInjector(object target, params object[] arguments);
}
\ No newline at end of file
diff --git a/src/Ninject/Injection/PropertyInjector.cs b/src/Ninject/Injection/PropertyInjector.cs
index fc1cfae9..f84c39cd 100644
--- a/src/Ninject/Injection/PropertyInjector.cs
+++ b/src/Ninject/Injection/PropertyInjector.cs
@@ -1,16 +1,32 @@
-#region License
-//
-// Author: Nate Kohari
-// Copyright (c) 2007-2010, Enkari, Ltd.
-//
-// Dual-licensed under the Apache License, Version 2.0, and the Microsoft Public License (Ms-PL).
-// See the file LICENSE.txt for details.
-//
-#endregion
+//-------------------------------------------------------------------------------------------------
+//
+// Copyright (c) 2007-2010, Enkari, Ltd.
+// Copyright (c) 2010-2016, Ninject Project Contributors
+// Authors: Nate Kohari (nate@enkari.com)
+// Remo Gloor (remo.gloor@gmail.com)
+//
+// 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.
+//
+//-------------------------------------------------------------------------------------------------
+
namespace Ninject.Injection
{
///
- /// A delegate that can inject values into a property.
+ /// Represents a delegate that can inject values into a property.
///
+ /// The property info.
+ /// The value to be injected to the property.
public delegate void PropertyInjector(object target, object value);
}
\ No newline at end of file
diff --git a/src/Ninject/Injection/ReflectionInjectorFactory.cs b/src/Ninject/Injection/ReflectionInjectorFactory.cs
index a1bc27ad..b4aeb514 100644
--- a/src/Ninject/Injection/ReflectionInjectorFactory.cs
+++ b/src/Ninject/Injection/ReflectionInjectorFactory.cs
@@ -1,20 +1,31 @@
-#region License
-//
-// Author: Nate Kohari
-// Copyright (c) 2007-2010, Enkari, Ltd.
-//
-// Dual-licensed under the Apache License, Version 2.0, and the Microsoft Public License (Ms-PL).
-// See the file LICENSE.txt for details.
-//
-#endregion
-#region Using Directives
-using System;
-using System.Reflection;
-using Ninject.Components;
-#endregion
+//-------------------------------------------------------------------------------------------------
+//
+// Copyright (c) 2007-2010, Enkari, Ltd.
+// Copyright (c) 2010-2016, Ninject Project Contributors
+// Authors: Nate Kohari (nate@enkari.com)
+// Remo Gloor (remo.gloor@gmail.com)
+//
+// 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.
+//
+//-------------------------------------------------------------------------------------------------
namespace Ninject.Injection
{
+ using System.Reflection;
+ using Ninject.Components;
+
///
/// Creates injectors from members via reflective invocation.
///
diff --git a/src/Ninject/KernelBase.cs b/src/Ninject/KernelBase.cs
index 0714a6bd..75710764 100644
--- a/src/Ninject/KernelBase.cs
+++ b/src/Ninject/KernelBase.cs
@@ -1,10 +1,25 @@
-//
-// Author: Nate Kohari
-// Copyright (c) 2007-2010, Enkari, Ltd.
-//
-// Dual-licensed under the Apache License, Version 2.0, and the Microsoft Public License (Ms-PL).
-// See the file LICENSE.txt for details.
-//
+//-------------------------------------------------------------------------------------------------
+//
+// Copyright (c) 2007-2010, Enkari, Ltd.
+// Copyright (c) 2010-2016, Ninject Project Contributors
+// Authors: Nate Kohari (nate@enkari.com)
+// Remo Gloor (remo.gloor@gmail.com)
+//
+// 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.
+//
+//-------------------------------------------------------------------------------------------------
namespace Ninject
{
@@ -17,7 +32,6 @@ namespace Ninject
using Ninject.Modules;
using Ninject.Parameters;
using Ninject.Planning.Bindings;
- using Ninject.Selection;
using Ninject.Syntax;
///
@@ -27,7 +41,7 @@ namespace Ninject
public abstract class KernelBase : BindingRoot, IKernel
{
private readonly object kernelLockObject = new object();
-
+
private readonly IKernelConfiguration kernelConfiguration;
private IReadOnlyKernel kernel;
@@ -72,7 +86,7 @@ protected KernelBase(IComponentContainer components, INinjectSettings settings,
this.kernelConfiguration = new KernelConfiguration(components, settings, modules);
this.kernelConfiguration.Bind().ToMethod(ctx => this);
this.kernelConfiguration.Bind().ToMethod(ctx => this).When(ctx => true);
- }
+ }
///
/// Gets the kernel settings.
@@ -90,19 +104,42 @@ public IComponentContainer Components
get { return this.kernelConfiguration.Components; }
}
+ private IReadOnlyKernel ReadOnlyKernel
+ {
+ get
+ {
+ if (!this.isDirty)
+ {
+ return this.kernel;
+ }
+
+ lock (this.kernelLockObject)
+ {
+ if (this.isDirty)
+ {
+ this.kernel = this.kernelConfiguration.BuildReadonlyKernel();
+ this.isDirty = false;
+ }
+
+ return this.kernel;
+ }
+ }
+ }
+
///
/// Releases resources held by the object.
///
+ /// True if called manually, otherwise by GC.
public override void Dispose(bool disposing)
{
- if (disposing && !IsDisposed)
+ if (disposing && !this.IsDisposed)
{
if (this.kernel != null)
{
this.kernel.Dispose();
}
- //this.kernelConfiguration.Dispose();
+ // this.kernelConfiguration.Dispose();
}
base.Dispose(disposing);
@@ -165,8 +202,8 @@ public void Load(IEnumerable m)
{
this.kernelConfiguration.Load(m);
this.isDirty = true;
- }
-
+ }
+
#if !NO_ASSEMBLY_SCANNING
///
/// Loads modules from the files that match the specified pattern(s).
@@ -174,25 +211,9 @@ public void Load(IEnumerable m)
/// The file patterns (i.e. "*.dll", "modules/*.rb") to match.
public void Load(IEnumerable filePatterns)
{
-#if PCL
- throw new NotImplementedException();
-#else
this.kernelConfiguration.Load(filePatterns);
this.isDirty = true;
-#endif
- }
-
-#if WINRT
- ///
- /// Loads modules from the files that match the specified pattern(s).
- ///
- /// The file patterns (i.e. "*.dll", "modules/*.rb") to match.
- public async System.Threading.Tasks.Task LoadAsync(IEnumerable filePatterns)
- {
- var moduleLoader = this.Components.Get();
- await moduleLoader.LoadModules(filePatterns);
}
-#endif
///
/// Loads modules defined in the specified assemblies.
@@ -207,19 +228,17 @@ public void Load(IEnumerable assemblies)
///
/// Does nothing on this framework
///
- ///
+ /// The file patterns (i.e. "*.dll", "modules/*.rb") to match.
public void Load(IEnumerable filePatterns)
{
-
}
///
/// Does nothing on this framework
///
- ///
+ /// The assemblies to search.
public void Load(IEnumerable assembly)
{
-
}
#endif //!NO_ASSEMBLY_SCANNING
@@ -233,28 +252,6 @@ public void Unload(string name)
this.isDirty = true;
}
- private IReadOnlyKernel ReadonlyKernel
- {
- get
- {
- if (!this.isDirty)
- {
- return this.kernel;
- }
-
- lock (this.kernelLockObject)
- {
- if (this.isDirty)
- {
- this.kernel = this.kernelConfiguration.BuildReadonlyKernel();
- this.isDirty = false;
- }
-
- return this.kernel;
- }
- }
- }
-
///
/// Injects the specified existing instance, without managing its lifecycle.
///
@@ -262,7 +259,7 @@ private IReadOnlyKernel ReadonlyKernel
/// The parameters to pass to the request.
public virtual void Inject(object instance, params IParameter[] parameters)
{
- this.ReadonlyKernel.Inject(instance, parameters);
+ this.ReadOnlyKernel.Inject(instance, parameters);
}
///
@@ -272,7 +269,7 @@ public virtual void Inject(object instance, params IParameter[] parameters)
/// if the instance was found and released; otherwise .
public virtual bool Release(object instance)
{
- return this.ReadonlyKernel.Release(instance);
+ return this.ReadOnlyKernel.Release(instance);
}
///
@@ -282,7 +279,7 @@ public virtual bool Release(object instance)
/// True if the request can be resolved; otherwise, false.
public virtual bool CanResolve(IRequest request)
{
- return this.ReadonlyKernel.CanResolve(request);
+ return this.ReadOnlyKernel.CanResolve(request);
}
///
@@ -295,7 +292,7 @@ public virtual bool CanResolve(IRequest request)
///
public virtual bool CanResolve(IRequest request, bool ignoreImplicitBindings)
{
- return this.ReadonlyKernel.CanResolve(request, ignoreImplicitBindings);
+ return this.ReadOnlyKernel.CanResolve(request, ignoreImplicitBindings);
}
///
@@ -306,8 +303,8 @@ public virtual bool CanResolve(IRequest request, bool ignoreImplicitBindings)
/// An enumerator of instances that match the request.
public virtual IEnumerable Resolve(IRequest request)
{
- return this.ReadonlyKernel.Resolve(request);
- }
+ return this.ReadOnlyKernel.Resolve(request);
+ }
///
/// Creates a request for the specified service.
@@ -320,7 +317,7 @@ public virtual IEnumerable Resolve(IRequest request)
/// The created request.
public virtual IRequest CreateRequest(Type service, Func constraint, IEnumerable parameters, bool isOptional, bool isUnique)
{
- return this.ReadonlyKernel.CreateRequest(service, constraint, parameters, isOptional, isUnique);
+ return this.ReadOnlyKernel.CreateRequest(service, constraint, parameters, isOptional, isUnique);
}
///
@@ -340,7 +337,7 @@ public virtual IActivationBlock BeginBlock()
public virtual IEnumerable GetBindings(Type service)
{
return this.kernelConfiguration.GetBindings(service);
- }
+ }
///
public IReadOnlyKernel BuildReadonlyKernel()
@@ -349,33 +346,33 @@ public IReadOnlyKernel BuildReadonlyKernel()
}
// Todo: Add
- //protected virtual IComparer GetBindingPrecedenceComparer()
- //{
+ // protected virtual IComparer GetBindingPrecedenceComparer()
+ // {
// return new BindingPrecedenceComparer();
- //}
+ // }
// Todo: Add
- //protected virtual Func SatifiesRequest(IRequest request)
- //{
+ // protected virtual Func SatifiesRequest(IRequest request)
+ // {
// return binding => binding.Matches(request) && request.Matches(binding);
- //}
+ // }
// Todo: Add
- //protected abstract void AddComponents();
+ // protected abstract void AddComponents();
// Todo: Add
- //protected virtual IContext CreateContext(IRequest request, IBinding binding)
- //{
+ // protected virtual IContext CreateContext(IRequest request, IBinding binding)
+ // {
// Ensure.ArgumentNotNull(request, "request");
// Ensure.ArgumentNotNull(binding, "binding");
- // return new Context(this, request, binding, this.Components.Get(), this.Components.Get(), this.Components.Get());
- //}
+ // return new Context(this, request, binding, this.Components.Get(), this.Components.Get(), this.Components.Get());
+ // }
///
public object GetService(Type serviceType)
- {
- return this.ReadonlyKernel.GetService(serviceType);
+ {
+ return this.ReadOnlyKernel.GetService(serviceType);
}
}
}
\ No newline at end of file
diff --git a/src/Ninject/KernelConfiguration.cs b/src/Ninject/KernelConfiguration.cs
index 42b62bc4..1ffc5ff2 100644
--- a/src/Ninject/KernelConfiguration.cs
+++ b/src/Ninject/KernelConfiguration.cs
@@ -1,7 +1,31 @@
-namespace Ninject
+//-------------------------------------------------------------------------------------------------
+//
+// Copyright (c) 2007-2010, Enkari, Ltd.
+// Copyright (c) 2010-2016, Ninject Project Contributors
+// Authors: Nate Kohari (nate@enkari.com)
+// Remo Gloor (remo.gloor@gmail.com)
+//
+// 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.
+//
+//-------------------------------------------------------------------------------------------------
+
+namespace Ninject
{
using System;
using System.Collections.Generic;
+ using System.Diagnostics.Contracts;
using System.Linq;
using System.Reflection;
@@ -60,14 +84,14 @@ public KernelConfiguration(INinjectSettings settings, params INinjectModule[] mo
/// The modules to load into the kernel.
public KernelConfiguration(IComponentContainer components, INinjectSettings settings, params INinjectModule[] modules)
{
- Ensure.ArgumentNotNull(components, "components");
- Ensure.ArgumentNotNull(settings, "settings");
- Ensure.ArgumentNotNull(modules, "modules");
+ Contract.Requires(components != null);
+ Contract.Requires(settings != null);
+ Contract.Requires(modules != null);
this.settings = settings;
this.Components = components;
-
+
components.KernelConfiguration = this;
this.AddComponents();
@@ -81,6 +105,9 @@ public KernelConfiguration(IComponentContainer components, INinjectSettings sett
this.Load(modules);
}
+ ///
+ public IComponentContainer Components { get; private set; }
+
///
public override INinjectSettings Settings
{
@@ -93,7 +120,7 @@ public override INinjectSettings Settings
///
public override void Unbind(Type service)
{
- Ensure.ArgumentNotNull(service, "service");
+ Contract.Requires(service != null);
this.bindings.RemoveAll(service);
}
@@ -101,7 +128,7 @@ public override void Unbind(Type service)
///
public override void AddBinding(IBinding binding)
{
- Ensure.ArgumentNotNull(binding, "binding");
+ Contract.Requires(binding != null);
this.bindings.Add(binding.Service, binding);
}
@@ -109,14 +136,11 @@ public override void AddBinding(IBinding binding)
///
public override void RemoveBinding(IBinding binding)
{
- Ensure.ArgumentNotNull(binding, "binding");
+ Contract.Requires(binding != null);
this.bindings.Remove(binding.Service, binding);
}
- ///
- public IComponentContainer Components { get; private set; }
-
///
public IEnumerable GetModules()
{
@@ -126,17 +150,17 @@ public IEnumerable GetModules()
///
public bool HasModule(string name)
{
- Ensure.ArgumentNotNullOrEmpty(name, "name");
+ Contract.Requires(name != null);
return this.modules.ContainsKey(name);
}
///
- public void Load(IEnumerable m)
+ public void Load(IEnumerable modules)
{
- Ensure.ArgumentNotNull(m, "modules");
+ Contract.Requires(this.modules != null);
- m = m.ToList();
- foreach (INinjectModule module in m)
+ modules = modules.ToList();
+ foreach (INinjectModule module in modules)
{
if (string.IsNullOrEmpty(module.Name))
{
@@ -155,7 +179,7 @@ public void Load(IEnumerable m)
this.modules.Add(module.Name, module);
}
- foreach (INinjectModule module in m)
+ foreach (INinjectModule module in modules)
{
module.OnVerifyRequiredModules();
}
@@ -165,12 +189,8 @@ public void Load(IEnumerable m)
///
public void Load(IEnumerable filePatterns)
{
-#if PCL
- throw new NotImplementedException("Platform assembly must be referenced by app");
-#else
var moduleLoader = this.Components.Get();
moduleLoader.LoadModules(filePatterns);
-#endif
}
///
@@ -183,7 +203,7 @@ public void Load(IEnumerable assemblies)
///
public void Unload(string name)
{
- Ensure.ArgumentNotNullOrEmpty(name, "name");
+ Contract.Requires(name != null);
INinjectModule module;
@@ -200,18 +220,18 @@ public void Unload(string name)
///
public IEnumerable GetBindings(Type service)
{
- Ensure.ArgumentNotNull(service, "service");
+ Contract.Requires(service != null);
var resolvers = this.Components.GetAll();
return resolvers.SelectMany(resolver => resolver.Resolve(
- bindings.Keys.ToDictionary(type => type, type => bindings[type]),
+ this.bindings.Keys.ToDictionary(type => type, type => this.bindings[type]),
service));
}
///
public IReadOnlyKernel BuildReadonlyKernel()
{
- var readonlyKernel = new ReadonlyKernel(
+ var readonlyKernel = new ReadOnlyKernel(
this.CloneBindings(),
this.Components.Get(),
this.Components.Get(),
@@ -225,67 +245,67 @@ public IReadOnlyKernel BuildReadonlyKernel()
return readonlyKernel;
}
- private Multimap CloneBindings()
- {
- // Todo: Clone
- return this.bindings;
- }
-
///
/// Adds components to the kernel during startup.
///
protected virtual void AddComponents()
{
- Components.Add();
- Components.Add();
- Components.Add();
- Components.Add();
+ this.Components.Add();
+ this.Components.Add();
+ this.Components.Add();
+ this.Components.Add();
- Components.Add();
- Components.Add();
- Components.Add();
+ this.Components.Add();
+ this.Components.Add();
+ this.Components.Add();
- Components.Add();
- if (!Settings.ActivationCacheDisabled)
+ this.Components.Add();
+ if (!this.Settings.ActivationCacheDisabled)
{
- Components.Add();
+ this.Components.Add();
}
- Components.Add();
- Components.Add();
- Components.Add();
- Components.Add();
- Components.Add();
- Components.Add();
+ this.Components.Add();
+ this.Components.Add();
+ this.Components.Add();
+ this.Components.Add();
+ this.Components.Add();
+ this.Components.Add();
- Components.Add();
+ this.Components.Add();
- Components.Add();
- Components.Add();
+ this.Components.Add();
+ this.Components.Add();
- Components.Add();
- Components.Add();
+ this.Components.Add();
+ this.Components.Add();
#if !NO_LCG
- if (!Settings.UseReflectionBasedInjection)
+ if (!this.Settings.UseReflectionBasedInjection)
{
- Components.Add();
+ this.Components.Add();
}
else
#endif
{
- Components.Add();
+ this.Components.Add();
}
- Components.Add();
- Components.Add();
- Components.Add();
+ this.Components.Add