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 Resolve(IRequest request) { - Ensure.ArgumentNotNull(request, "request"); - return Parent.Resolve(request); + Contract.Requires(request != null); + return this.Parent.Resolve(request); } /// @@ -121,8 +110,8 @@ public IEnumerable Resolve(IRequest request) /// The created request. public virtual IRequest CreateRequest(Type service, Func constraint, IEnumerable parameters, bool isOptional, bool isUnique) { - Ensure.ArgumentNotNull(service, "service"); - Ensure.ArgumentNotNull(parameters, "parameters"); + Contract.Requires(service != null); + Contract.Requires(parameters != null); return new Request(service, constraint, parameters, () => this, isOptional, isUnique); } @@ -131,10 +120,9 @@ public virtual IRequest CreateRequest(Type service, Func /// /// The instance to release. /// if the instance was found and released; otherwise . - /// public bool Release(object instance) { - return Parent.Release(instance); + return this.Parent.Release(instance); } } } \ No newline at end of file diff --git a/src/Ninject/Activation/Blocks/IActivationBlock.cs b/src/Ninject/Activation/Blocks/IActivationBlock.cs index c53ec569..4a0a56ac 100644 --- a/src/Ninject/Activation/Blocks/IActivationBlock.cs +++ b/src/Ninject/Activation/Blocks/IActivationBlock.cs @@ -1,23 +1,36 @@ -#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; -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 Ninject.Infrastructure.Disposal; + 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 interface IActivationBlock : IResolutionRoot, INotifyWhenDisposed { } + public interface IActivationBlock : IResolutionRoot, IDisposableObject + { + } } \ No newline at end of file diff --git a/src/Ninject/Activation/Caching/ActivationCache.cs b/src/Ninject/Activation/Caching/ActivationCache.cs index a6db39d8..23d118b2 100644 --- a/src/Ninject/Activation/Caching/ActivationCache.cs +++ b/src/Ninject/Activation/Caching/ActivationCache.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; using System.Collections.Generic; - using System.Linq; + using System.Diagnostics.Contracts; using Ninject.Components; using Ninject.Infrastructure; @@ -11,17 +33,6 @@ namespace Ninject.Activation.Caching /// 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(); + this.Components.Add(); + this.Components.Add(); #if !NO_ASSEMBLY_SCANNING - Components.Add(); - Components.Add(); - Components.Add(); + this.Components.Add(); + this.Components.Add(); + this.Components.Add(); #endif } + + private Multimap CloneBindings() + { + // Todo: Clone + return this.bindings; + } } } \ No newline at end of file diff --git a/src/Ninject/Modules/AssemblyNameRetriever.cs b/src/Ninject/Modules/AssemblyNameRetriever.cs index 530dd06a..71d57e31 100644 --- a/src/Ninject/Modules/AssemblyNameRetriever.cs +++ b/src/Ninject/Modules/AssemblyNameRetriever.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,8 +22,6 @@ // //------------------------------------------------------------------------------- -using System.Threading.Tasks; - #if !NO_ASSEMBLY_SCANNING namespace Ninject.Modules { @@ -29,12 +30,8 @@ namespace Ninject.Modules using System.IO; using System.Linq; using System.Reflection; - - using Ninject.Components; - -#if WINRT using System.Threading.Tasks; -#endif + using Ninject.Components; /// /// Retrieves assembly names from file names using a temporary app domain. @@ -47,18 +44,8 @@ public class AssemblyNameRetriever : NinjectComponent, IAssemblyNameRetriever /// The filenames. /// The filter. /// All assembly names of the assemblies in the given files that match the filter. - public -#if !WINRT - IEnumerable -#else - System.Threading.Tasks.Task> -#endif - GetAssemblyNames(IEnumerable filenames, Predicate filter) + public IEnumerable GetAssemblyNames(IEnumerable filenames, Predicate filter) { -#if PCL - throw new NotImplementedException(); -#else -#if !NETSTANDARD1_3 var assemblyCheckerType = typeof(AssemblyChecker); var temporaryDomain = CreateTemporaryAppDomain(); try @@ -68,23 +55,13 @@ public class AssemblyNameRetriever : NinjectComponent, IAssemblyNameRetriever assemblyCheckerType.FullName ?? string.Empty); return checker.GetAssemblyNames(filenames.ToArray(), filter); -#else - var checker = new AssemblyCheckerWinRT(); - return checker.GetAssemblyListAsync(filenames.ToArray(), filter); -#endif - -#if !NETSTANDARD1_3 } finally { AppDomain.Unload(temporaryDomain); } -#endif -#endif } - -#if !NETSTANDARD1_3 /// /// Creates a temporary app domain. /// @@ -146,65 +123,6 @@ public IEnumerable GetAssemblyNames(IEnumerable filenames, return result; } } -#else - private sealed class AssemblyCheckerWinRT - { - //public IEnumerable GetAssemblyNames(IEnumerable filenames, Predicate filter) - //{ - // return GetAssemblyListAsync(filenames, filter).Result; - //} - - public async Task> GetAssemblyListAsync(IEnumerable filenames, Predicate filter) - { - var folder = Windows.ApplicationModel.Package.Current.InstalledLocation; - - var result = new List(); - var files = (await folder.GetFilesAsync()).ToDictionary(k => k.Name.ToLowerInvariant(), e => (Windows.Storage.StorageFile)e); - - foreach (var filename in filenames) - { - Assembly assembly; - - if (files.ContainsKey(filename.ToLowerInvariant())) - { - try - { - AssemblyName name = new AssemblyName() { Name = files[filename.ToLowerInvariant()].DisplayName }; - assembly = Assembly.Load(name); - } - catch (BadImageFormatException) - { - continue; - } - } - else - { - try - { - AssemblyName name = new AssemblyName() { Name = filename }; - assembly = Assembly.Load(name); - } - catch (FileNotFoundException) - { - continue; - } - } - - if (filter(assembly)) - { -#if !WINRT - result.Add(assembly.GetName()); -#else - result.Add(new AssemblyName() {Name = assembly.GetName().Name}); -#endif - } - } - - return result; - } - } -#endif - } } #endif \ No newline at end of file diff --git a/src/Ninject/Modules/CompiledModuleLoaderPlugin.cs b/src/Ninject/Modules/CompiledModuleLoaderPlugin.cs index b7512b52..7e2f8ec5 100644 --- a/src/Ninject/Modules/CompiledModuleLoaderPlugin.cs +++ b/src/Ninject/Modules/CompiledModuleLoaderPlugin.cs @@ -1,10 +1,11 @@ //------------------------------------------------------------------------------- +//------------------------------------------------------------------------------------------------- // -// 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 @@ -21,32 +22,31 @@ // //------------------------------------------------------------------------------- -using System; - #if !NO_ASSEMBLY_SCANNING namespace Ninject.Modules { + using System; + using System.Collections.Generic; using System.Linq; using System.Reflection; - using Ninject.Components; using Ninject.Infrastructure.Language; - + /// /// Loads modules from compiled assemblies. /// public class CompiledModuleLoaderPlugin : NinjectComponent, IModuleLoaderPlugin { /// - /// The assembly name retriever. + /// The file extensions that are supported. /// - private readonly IAssemblyNameRetriever assemblyNameRetriever; + private static readonly string[] Extensions = { ".dll" }; /// - /// The file extensions that are supported. + /// The assembly name retriever. /// - private static readonly string[] Extensions = { ".dll" }; + private readonly IAssemblyNameRetriever assemblyNameRetriever; /// /// Initializes a new instance of the class. @@ -76,26 +76,12 @@ public IEnumerable SupportedExtensions /// Loads modules from the specified files. /// /// The names of the files to load modules from. - public -#if !WINRT - void -#else - async System.Threading.Tasks.Task -#endif - LoadModules(IEnumerable filenames) + public void LoadModules(IEnumerable filenames) { -#if PCL - throw new NotImplementedException(); -#else - var assembliesWithModules = -#if WINRT - await -#endif + var assembliesWithModules = this.assemblyNameRetriever.GetAssemblyNames(filenames, asm => asm.HasNinjectModules()); - this.KernelConfiguration.Load(assembliesWithModules.Select(asm => Assembly.Load(asm))); -#endif } } } diff --git a/src/Ninject/Modules/IAssemblyNameRetriever.cs b/src/Ninject/Modules/IAssemblyNameRetriever.cs index d54ea216..a7f3c610 100644 --- a/src/Ninject/Modules/IAssemblyNameRetriever.cs +++ b/src/Ninject/Modules/IAssemblyNameRetriever.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,7 +22,6 @@ // //------------------------------------------------------------------------------- -#if !NO_ASSEMBLY_SCANNING namespace Ninject.Modules { using System; @@ -39,12 +41,6 @@ public interface IAssemblyNameRetriever : INinjectComponent /// The filenames. /// The filter. /// All assembly names of the assemblies in the given files that match the filter. -#if !WINRT - IEnumerable -#else - System.Threading.Tasks.Task> -#endif - GetAssemblyNames(IEnumerable filenames, Predicate filter); + IEnumerable GetAssemblyNames(IEnumerable filenames, Predicate filter); } -} -#endif \ No newline at end of file +} \ No newline at end of file diff --git a/src/Ninject/Modules/IModuleLoader.cs b/src/Ninject/Modules/IModuleLoader.cs index 26bed80c..880d1617 100644 --- a/src/Ninject/Modules/IModuleLoader.cs +++ b/src/Ninject/Modules/IModuleLoader.cs @@ -1,40 +1,40 @@ -#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 !SILVERLIGHT -#region Using Directives -using System; -using System.Collections.Generic; -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.Modules { + using System.Collections.Generic; + using Ninject.Components; + /// /// Finds modules defined in external files. /// public interface IModuleLoader : INinjectComponent { -#if !PCL // PCL can't contain this method as the signature differs /// /// Loads any modules found in the files that match the specified patterns. /// /// The patterns to search. - -#if !WINRT - void -#else - System.Threading.Tasks.Task -#endif - LoadModules(IEnumerable patterns); -#endif + void LoadModules(IEnumerable patterns); } - -} -#endif \ No newline at end of file +} \ No newline at end of file diff --git a/src/Ninject/Modules/IModuleLoaderPlugin.cs b/src/Ninject/Modules/IModuleLoaderPlugin.cs index 77863815..1a4b95b7 100644 --- a/src/Ninject/Modules/IModuleLoaderPlugin.cs +++ b/src/Ninject/Modules/IModuleLoaderPlugin.cs @@ -1,21 +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 -#if !SILVERLIGHT -#region Using Directives -using System; -using System.Collections.Generic; -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.Modules { + using System.Collections.Generic; + using Ninject.Components; + /// /// Loads modules at runtime by searching external files. /// @@ -30,12 +40,6 @@ public interface IModuleLoaderPlugin : INinjectComponent /// Loads modules from the specified files. /// /// The names of the files to load modules from. -#if !WINRT - void -#else - System.Threading.Tasks.Task -#endif - LoadModules(IEnumerable filenames); + void LoadModules(IEnumerable filenames); } -} -#endif \ No newline at end of file +} \ No newline at end of file diff --git a/src/Ninject/Modules/INinjectModule.cs b/src/Ninject/Modules/INinjectModule.cs index ac471a96..772595ae 100644 --- a/src/Ninject/Modules/INinjectModule.cs +++ b/src/Ninject/Modules/INinjectModule.cs @@ -1,17 +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; -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.Modules { @@ -25,7 +33,7 @@ public interface INinjectModule /// /// The kernel configuration that the module is loaded into. IKernelConfiguration KernelConfiguration { get; } - + /// /// Gets the module's name. /// diff --git a/src/Ninject/Modules/ModuleLoader.cs b/src/Ninject/Modules/ModuleLoader.cs index f050ed3f..023c6abd 100644 --- a/src/Ninject/Modules/ModuleLoader.cs +++ b/src/Ninject/Modules/ModuleLoader.cs @@ -1,94 +1,79 @@ -#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. +// +//------------------------------------------------------------------------------------------------- #if !NO_ASSEMBLY_SCANNING -#region Using Directives - -using System; -using System.Collections.Generic; -using System.IO; -using System.Linq; -using Ninject.Components; -using Ninject.Infrastructure; -#endregion - namespace Ninject.Modules { + using System; + using System.Collections.Generic; + using System.IO; + using System.Linq; + using Ninject.Components; + using Ninject.Infrastructure; + /// /// Automatically finds and loads modules from assemblies. /// public class ModuleLoader : NinjectComponent, IModuleLoader { - /// - /// Gets or sets the kernel into which modules will be loaded. - /// - public IKernelConfiguration KernelConfiguration { get; private set; } - /// /// Initializes a new instance of the class. /// /// The kernel configuration into which modules will be loaded. public ModuleLoader(IKernelConfiguration kernelConfiguration) { - KernelConfiguration = kernelConfiguration; + this.KernelConfiguration = kernelConfiguration; } -#if !PCL + + /// + /// Gets the kernel into which modules will be loaded. + /// + public IKernelConfiguration KernelConfiguration { get; private set; } + /// /// Loads any modules found in the files that match the specified patterns. /// /// The patterns to search. - public -#if !WINRT - void -#else - async System.Threading.Tasks.Task -#endif - LoadModules(IEnumerable patterns) + public void LoadModules(IEnumerable patterns) { -#if PCL - throw new NotImplementedException(); -#else - var plugins = KernelConfiguration.Components.GetAll(); + var plugins = this.KernelConfiguration.Components.GetAll(); var fileGroups = patterns -#if !WINRT .SelectMany(pattern => GetFilesMatchingPattern(pattern)) .GroupBy(filename => Path.GetExtension(filename).ToLowerInvariant()); -#else - .GroupBy(filename => GetExtension(filename).ToLowerInvariant()); -#endif foreach (var fileGroup in fileGroups) { - string extension = fileGroup.Key; - IModuleLoaderPlugin plugin = plugins.Where(p => p.SupportedExtensions.Contains(extension)).FirstOrDefault(); + var extension = fileGroup.Key; + var plugin = plugins.Where(p => p.SupportedExtensions.Contains(extension)).FirstOrDefault(); if (plugin != null) -#if WINRT - await -#endif + { plugin.LoadModules(fileGroup); + } } -#endif } -#endif -#if !PCL -#if WINRT - private static string GetExtension(string filename) - { - var i = filename.LastIndexOf('.'); - return filename.Substring(i); - } -#endif -#if !WINRT private static IEnumerable GetFilesMatchingPattern(string pattern) { return NormalizePaths(Path.GetDirectoryName(pattern)) @@ -104,20 +89,14 @@ private static IEnumerable NormalizePaths(string path) private static IEnumerable GetBaseDirectories() { -#if ANDROID - return new[] { Android.App.Application.Context.FilesDir.AbsolutePath }; -#else var baseDirectory = AppDomain.CurrentDomain.BaseDirectory; var searchPath = AppDomain.CurrentDomain.RelativeSearchPath; - return String.IsNullOrEmpty(searchPath) - ? new[] {baseDirectory} - : searchPath.Split(new[] {Path.PathSeparator}, StringSplitOptions.RemoveEmptyEntries) + return string.IsNullOrEmpty(searchPath) + ? new[] { baseDirectory } + : searchPath.Split(new[] { Path.PathSeparator }, StringSplitOptions.RemoveEmptyEntries) .Select(path => Path.Combine(baseDirectory, path)); -#endif } -#endif -#endif } } #endif //!NO_ASSEMBLY_SCANNING \ No newline at end of file diff --git a/src/Ninject/Modules/NinjectModule.cs b/src/Ninject/Modules/NinjectModule.cs index 462c5337..fbc4927a 100644 --- a/src/Ninject/Modules/NinjectModule.cs +++ b/src/Ninject/Modules/NinjectModule.cs @@ -1,10 +1,11 @@ //------------------------------------------------------------------------------- +//------------------------------------------------------------------------------------------------- // -// 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 @@ -21,14 +22,11 @@ // //------------------------------------------------------------------------------- -using Ninject.Infrastructure.Language; - namespace Ninject.Modules { using System; using System.Collections.Generic; - - using Ninject.Infrastructure; + using Ninject.Infrastructure.Language; using Ninject.Planning.Bindings; using Ninject.Syntax; @@ -70,20 +68,20 @@ public override INinjectSettings Settings /// /// The kernel configuration that the module is loaded into. public IKernelConfiguration KernelConfiguration { get; private set; } - + /// /// Gets the module's name. Only a single module with a given name can be loaded at one time. /// public virtual string Name { - get { return GetType().FullName; } + get { return this.GetType().FullName; } } /// /// Gets the bindings that were registered by the module. /// public ICollection Bindings { get; private set; } - + /// /// Called when the module is loaded into a kernel. /// diff --git a/src/Ninject/Ninject.Net45.csproj b/src/Ninject/Ninject.Net45.csproj deleted file mode 100644 index 2e264e70..00000000 --- a/src/Ninject/Ninject.Net45.csproj +++ /dev/null @@ -1,242 +0,0 @@ - - - - Debug - AnyCPU - 9.0.30729 - 2.0 - {37AAD36A-2252-43D6-8BC4-F63BFEFDFECB} - Library - Properties - Ninject - Ninject - 512 - true - ..\Ninject.snk - v4.5 - - - - true - full - false - bin\NET4\Debug\ - TRACE;DEBUG - prompt - 4 - - - - - pdbonly - true - bin\NET4\Release\ - TRACE - prompt - 4 - true - bin\NET4\Release\Ninject.xml - - - - - - - Properties\SharedAssemblyInfo.cs - - - - - - Code - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - Code - - - Code - - - - Code - - - Code - - - - - - Code - - - Code - - - Code - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - \ No newline at end of file diff --git a/src/Ninject/Ninject.Net45.project.json b/src/Ninject/Ninject.Net45.project.json deleted file mode 100644 index a3705880..00000000 --- a/src/Ninject/Ninject.Net45.project.json +++ /dev/null @@ -1,11 +0,0 @@ -{ - "dependencies": { - }, - "frameworks": { - ".NETFramework,Version=v4.5": {} - }, - "supports": {}, - "runtimes": { - "win": {} - } -} \ No newline at end of file diff --git a/src/Ninject/Ninject.csproj b/src/Ninject/Ninject.csproj deleted file mode 100644 index ed473253..00000000 --- a/src/Ninject/Ninject.csproj +++ /dev/null @@ -1,257 +0,0 @@ - - - - - Debug - AnyCPU - {ADF369E2-6B9E-4D56-9B82-D273AE41EC2D} - Library - Properties - Ninject - Ninject - v5.0 - - - 512 - true - ..\Ninject.snk - - - 3.5 - - publish\ - true - Disk - false - Foreground - 7 - Days - false - false - true - 0 - 1.0.0.%2a - false - false - true - {786C830F-07A1-408B-BD7F-6EE04809D6DB};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC} - 14.0 - obj\netstandard1.3\ - - - true - full - false - bin\netstandard1.3\Debug\ - TRACE;DEBUG;NETSTANDARD1_3;NO_LCG;NO_ASSEMBLY_SCANNING;NO_EXCEPTION_SERIALIZATION - prompt - 4 - - - true - AllRules.ruleset - false - - - pdbonly - true - bin\netstandard1.3\Release\ - TRACE;NETSTANDARD1_3;NO_LCG;NO_ASSEMBLY_SCANNING;NO_EXCEPTION_SERIALIZATION - prompt - 4 - bin\netstandard1.3\Release\Ninject.xml - true - - - true - - - ..\Ninject.snk - - - - Properties\SharedAssemblyInfo.cs - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - Ninject.snk - - - - - - \ No newline at end of file diff --git a/src/Ninject/Ninject.project.json b/src/Ninject/Ninject.project.json deleted file mode 100644 index d68421fa..00000000 --- a/src/Ninject/Ninject.project.json +++ /dev/null @@ -1,11 +0,0 @@ -{ - "supports": {}, - "dependencies": { - "NETStandard.Library": "1.6.0", - "System.ComponentModel": "4.0.1", - "System.Reflection.TypeExtensions": "4.1.0" - }, - "frameworks": { - "netstandard1.3": {} - } -} \ No newline at end of file diff --git a/src/Ninject/Ninject.xproj b/src/Ninject/Ninject.xproj new file mode 100644 index 00000000..d5c25050 --- /dev/null +++ b/src/Ninject/Ninject.xproj @@ -0,0 +1,19 @@ + + + + 14.0 + $(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion) + + + + adf369e2-6b9e-4d56-9b82-d273ae41ec2d + Ninject + .\obj + .\bin\ + v4.5.2 + + + 2.0 + + + diff --git a/src/Ninject/NinjectSettings.cs b/src/Ninject/NinjectSettings.cs index 53ebc0f4..96a1513c 100644 --- a/src/Ninject/NinjectSettings.cs +++ b/src/Ninject/NinjectSettings.cs @@ -1,22 +1,33 @@ -#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; -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 { + using System; + using System.Collections.Generic; + using Ninject.Activation; + using Ninject.Infrastructure; + /// /// Contains configuration options for Ninject. /// @@ -27,7 +38,8 @@ public class NinjectSettings : INinjectSettings /// /// Initializes a new instance of the class. /// - public NinjectSettings() : this(new Dictionary()) + public NinjectSettings() + : this(new Dictionary()) { } @@ -38,26 +50,18 @@ public NinjectSettings() : this(new Dictionary()) private NinjectSettings(IDictionary values) { this.values = values; - -#if SILVERLIGHT - InjectNonPublic = false; - InjectParentPrivateProperties = false; - -#endif - #if NO_LCG - UseReflectionBasedInjection = false; + this.UseReflectionBasedInjection = false; #endif } - /// /// Gets or sets the attribute that indicates that a member should be injected. /// public Type InjectAttribute { - get { return Get("InjectAttribute", typeof(InjectAttribute)); } - set { Set("InjectAttribute", value); } + get { return this.Get("InjectAttribute", typeof(InjectAttribute)); } + set { this.Set("InjectAttribute", value); } } /// @@ -65,8 +69,8 @@ public Type InjectAttribute /// public TimeSpan CachePruningInterval { - get { return Get("CachePruningInterval", TimeSpan.FromSeconds(30)); } - set { Set("CachePruningInterval", value); } + get { return this.Get("CachePruningInterval", TimeSpan.FromSeconds(30)); } + set { this.Set("CachePruningInterval", value); } } /// @@ -74,18 +78,17 @@ public TimeSpan CachePruningInterval /// public Func DefaultScopeCallback { - get { return Get("DefaultScopeCallback", StandardScopeCallbacks.Transient); } - set { Set("DefaultScopeCallback", value); } + get { return this.Get("DefaultScopeCallback", StandardScopeCallbacks.Transient); } + set { this.Set("DefaultScopeCallback", value); } } - /// /// Gets or sets a value indicating whether the kernel should automatically load extensions at startup. /// public bool LoadExtensions { - get { return Get("LoadExtensions", true); } - set { Set("LoadExtensions", value); } + get { return this.Get("LoadExtensions", true); } + set { this.Set("LoadExtensions", value); } } /// @@ -93,31 +96,31 @@ public bool LoadExtensions /// public string[] ExtensionSearchPatterns { - get { return Get("ExtensionSearchPatterns", new [] { "Ninject.Extensions.*.dll", "Ninject.Web*.dll" }); } - set { Set("ExtensionSearchPatterns", value); } + get { return this.Get("ExtensionSearchPatterns", new[] { "Ninject.Extensions.*.dll", "Ninject.Web*.dll" }); } + set { this.Set("ExtensionSearchPatterns", value); } } /// - /// Gets a value indicating whether Ninject should use reflection-based injection instead of + /// Gets or sets a value indicating whether Ninject should use reflection-based injection instead of /// the (usually faster) lightweight code generation system. /// public bool UseReflectionBasedInjection { - get { return Get("UseReflectionBasedInjection", false); } - set { Set("UseReflectionBasedInjection", value); } + get { return this.Get("UseReflectionBasedInjection", false); } + set { this.Set("UseReflectionBasedInjection", value); } } - + /// - /// Gets a value indicating whether Ninject should inject non public members. + /// Gets or sets a value indicating whether Ninject should inject non public members. /// public bool InjectNonPublic { - get { return Get("InjectNonPublic", false); } - set { Set("InjectNonPublic", value); } + get { return this.Get("InjectNonPublic", false); } + set { this.Set("InjectNonPublic", value); } } /// - /// 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 @@ -137,7 +140,7 @@ public bool InjectParentPrivateProperties /// Bind{IA}().ToMethod(ctx => kernel.Get{IA}(); /// /// - /// true if activation cache is disabled; otherwise, false. + /// true if activation cache is disabled; otherwise, false. /// public bool ActivationCacheDisabled { @@ -150,7 +153,7 @@ public bool ActivationCacheDisabled /// By default this is disabled and whenever a provider returns null an exception is thrown. /// /// - /// true if null is allowed as injected value otherwise false. + /// true if null is allowed as injected value otherwise false. /// public bool AllowNullInjection { @@ -191,4 +194,4 @@ public INinjectSettings Clone() return new NinjectSettings(clonedValues); } } -} +} \ No newline at end of file diff --git a/src/Ninject/Parameters/ConstructorArgument.cs b/src/Ninject/Parameters/ConstructorArgument.cs index dc56b790..2277e75d 100644 --- a/src/Ninject/Parameters/ConstructorArgument.cs +++ b/src/Ninject/Parameters/ConstructorArgument.cs @@ -1,10 +1,11 @@ //------------------------------------------------------------------------------- +//------------------------------------------------------------------------------------------------- // -// 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 diff --git a/src/Ninject/Parameters/IConstructorArgument.cs b/src/Ninject/Parameters/IConstructorArgument.cs index f36de64c..bed38016 100644 --- a/src/Ninject/Parameters/IConstructorArgument.cs +++ b/src/Ninject/Parameters/IConstructorArgument.cs @@ -1,4 +1,27 @@ -namespace Ninject.Parameters +//------------------------------------------------------------------------------------------------- +// +// 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.Parameters { using Ninject.Activation; using Ninject.Planning.Targets; diff --git a/src/Ninject/Parameters/IParameter.cs b/src/Ninject/Parameters/IParameter.cs index b0e3c127..775abf58 100644 --- a/src/Ninject/Parameters/IParameter.cs +++ b/src/Ninject/Parameters/IParameter.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.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.Parameters { + using System; + using Ninject.Activation; using Ninject.Planning.Targets; /// diff --git a/src/Ninject/Parameters/IPropertyValue.cs b/src/Ninject/Parameters/IPropertyValue.cs index 1dffffc1..abcfa291 100644 --- a/src/Ninject/Parameters/IPropertyValue.cs +++ b/src/Ninject/Parameters/IPropertyValue.cs @@ -1,8 +1,11 @@ //------------------------------------------------------------------------------- +//------------------------------------------------------------------------------------------------- // -// Copyright (c) 2009-2013 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 @@ -25,6 +28,6 @@ namespace Ninject.Parameters /// Overrides the injected value of a property. /// public interface IPropertyValue : IParameter - { + { } } \ No newline at end of file diff --git a/src/Ninject/Parameters/Parameter.cs b/src/Ninject/Parameters/Parameter.cs index 58d21daf..52f60c53 100644 --- a/src/Ninject/Parameters/Parameter.cs +++ b/src/Ninject/Parameters/Parameter.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.Activation; -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.Parameters { + using System; + using Ninject.Activation; using Ninject.Planning.Targets; /// @@ -22,28 +32,16 @@ namespace Ninject.Parameters /// public class Parameter : IParameter { - /// - /// Gets the name of the parameter. - /// - public string Name { get; private set; } - - /// - /// Gets a value indicating whether the parameter should be inherited into child requests. - /// - public bool ShouldInherit { get; private set; } - - /// - /// Gets or sets the callback that will be triggered to get the parameter's value. - /// - public Func ValueCallback { get; internal set; } - /// /// Initializes a new instance of the class. /// /// The name of the parameter. /// The value of the parameter. /// Whether the parameter should be inherited into child requests. - public Parameter(string name, object value, bool shouldInherit) : this(name, (ctx, target) => value, shouldInherit) { } + public Parameter(string name, object value, bool shouldInherit) + : this(name, (ctx, target) => value, shouldInherit) + { + } /// /// Initializes a new instance of the class. @@ -53,9 +51,9 @@ public class Parameter : IParameter /// Whether the parameter should be inherited into child requests. public Parameter(string name, Func valueCallback, bool shouldInherit) { - Name = name; - ValueCallback = (ctx, target) => valueCallback(ctx); - ShouldInherit = shouldInherit; + this.Name = name; + this.ValueCallback = (ctx, target) => valueCallback(ctx); + this.ShouldInherit = shouldInherit; } /// @@ -66,11 +64,26 @@ public Parameter(string name, Func valueCallback, bool shouldI /// Whether the parameter should be inherited into child requests. public Parameter(string name, Func valueCallback, bool shouldInherit) { - Name = name; - ValueCallback = valueCallback; - ShouldInherit = shouldInherit; + this.Name = name; + this.ValueCallback = valueCallback; + this.ShouldInherit = shouldInherit; } - + + /// + /// Gets the name of the parameter. + /// + public string Name { get; private set; } + + /// + /// Gets a value indicating whether the parameter should be inherited into child requests. + /// + public bool ShouldInherit { get; private set; } + + /// + /// Gets the callback that will be triggered to get the parameter's value. + /// + public Func ValueCallback { get; internal set; } + /// /// Gets the value for the parameter within the specified context. /// @@ -79,7 +92,7 @@ public Parameter(string name, Func valueCallback, boo /// The value for the parameter. public object GetValue(IContext context, ITarget target) { - return ValueCallback(context, target); + return this.ValueCallback(context, target); } /// @@ -90,7 +103,7 @@ public object GetValue(IContext context, ITarget target) public override bool Equals(object obj) { var parameter = obj as IParameter; - return parameter != null ? Equals(parameter) : base.Equals(obj); + return parameter != null ? this.Equals(parameter) : base.Equals(obj); } /// @@ -99,7 +112,7 @@ public override bool Equals(object obj) /// A hash code for the object. public override int GetHashCode() { - return GetType().GetHashCode() ^ Name.GetHashCode(); + return this.GetType().GetHashCode() ^ this.Name.GetHashCode(); } /// @@ -109,7 +122,7 @@ public override int GetHashCode() /// True if the objects are equal; otherwise false public bool Equals(IParameter other) { - return other.GetType() == GetType() && other.Name.Equals(Name); + return other.GetType() == this.GetType() && other.Name.Equals(this.Name); } } } \ No newline at end of file diff --git a/src/Ninject/Parameters/PropertyValue.cs b/src/Ninject/Parameters/PropertyValue.cs index 566a73c1..c2ae67c1 100644 --- a/src/Ninject/Parameters/PropertyValue.cs +++ b/src/Ninject/Parameters/PropertyValue.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.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.Parameters { + using System; + using Ninject.Activation; using Ninject.Planning.Targets; /// @@ -26,20 +37,29 @@ public class PropertyValue : Parameter, IPropertyValue /// /// The name of the property to override. /// The value to inject into the property. - public PropertyValue(string name, object value) : base(name, value, false) { } + public PropertyValue(string name, object value) + : base(name, value, false) + { + } /// /// Initializes a new instance of the class. /// /// The name of the property to override. /// The callback to invoke to get the value that should be injected. - public PropertyValue(string name, Func valueCallback) : base(name, valueCallback, false) { } + public PropertyValue(string name, Func valueCallback) + : base(name, valueCallback, false) + { + } /// /// Initializes a new instance of the class. /// /// The name of the property to override. /// The callback to invoke to get the value that should be injected. - public PropertyValue(string name, Func valueCallback) : base(name, valueCallback, false) { } + public PropertyValue(string name, Func valueCallback) + : base(name, valueCallback, false) + { + } } } \ No newline at end of file diff --git a/src/Ninject/Parameters/TypeMatchingConstructorArgument.cs b/src/Ninject/Parameters/TypeMatchingConstructorArgument.cs index 239fc50c..0a4ee540 100644 --- a/src/Ninject/Parameters/TypeMatchingConstructorArgument.cs +++ b/src/Ninject/Parameters/TypeMatchingConstructorArgument.cs @@ -1,8 +1,11 @@ //------------------------------------------------------------------------------- +//------------------------------------------------------------------------------------------------- // -// Copyright (c) 2009-2013 Ninject Project Contributors -// Authors: Ivan Appert (iappert@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 @@ -22,7 +25,6 @@ namespace Ninject.Parameters { using System; using Ninject.Activation; - using Ninject.Infrastructure; using Ninject.Planning.Targets; /// diff --git a/src/Ninject/Parameters/WeakConstructorArgument.cs b/src/Ninject/Parameters/WeakConstructorArgument.cs index 14727b41..7e1ea54c 100644 --- a/src/Ninject/Parameters/WeakConstructorArgument.cs +++ b/src/Ninject/Parameters/WeakConstructorArgument.cs @@ -1,8 +1,11 @@ //------------------------------------------------------------------------------- +//------------------------------------------------------------------------------------------------- // -// Copyright (c) 2009-2013 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 @@ -37,7 +40,7 @@ public class WeakConstructorArgument : Parameter, IConstructorArgument private readonly WeakReference weakReference; /// - /// Initializes a new instance of the class. + /// Initializes a new instance of the class. /// /// The name of the argument to override. /// The value to inject into the property. @@ -47,7 +50,7 @@ public WeakConstructorArgument(string name, object value) } /// - /// Initializes a new instance of the class. + /// Initializes a new instance of the class. /// /// The name of the argument to override. /// The value to inject into the property. diff --git a/src/Ninject/Parameters/WeakPropertyValue.cs b/src/Ninject/Parameters/WeakPropertyValue.cs index 78736e37..381dd3e5 100644 --- a/src/Ninject/Parameters/WeakPropertyValue.cs +++ b/src/Ninject/Parameters/WeakPropertyValue.cs @@ -1,8 +1,11 @@ //------------------------------------------------------------------------------- +//------------------------------------------------------------------------------------------------- // -// Copyright (c) 2009-2013 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 @@ -40,8 +43,7 @@ public WeakPropertyValue(string name, object value) : base(name, (object)null, false) { this.weakReference = new WeakReference(value); - this.ValueCallback = (ctx, target) => this.weakReference.Target; + this.ValueCallback = (ctx, target) => this.weakReference.Target; } - } } \ No newline at end of file diff --git a/src/Ninject/Planning/Bindings/Binding.cs b/src/Ninject/Planning/Bindings/Binding.cs index 537af20c..8e956484 100644 --- a/src/Ninject/Planning/Bindings/Binding.cs +++ b/src/Ninject/Planning/Bindings/Binding.cs @@ -1,22 +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; -using Ninject.Infrastructure; -using Ninject.Parameters; -#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.Planning.Bindings { + using System; + using System.Collections.Generic; + using Ninject.Activation; + using Ninject.Parameters; using Ninject.Selection; /// @@ -46,7 +56,7 @@ public Binding(Type service, IBindingConfiguration configuration) } /// - /// Gets or sets the binding configuration. + /// Gets the binding configuration. /// /// The binding configuration. public IBindingConfiguration BindingConfiguration { get; private set; } @@ -59,7 +69,6 @@ public Binding(Type service, IBindingConfiguration configuration) /// /// Gets the binding's metadata. /// - /// public IBindingMetadata Metadata { get @@ -71,7 +80,6 @@ public IBindingMetadata Metadata /// /// Gets or sets the type of target for the binding. /// - /// public BindingTarget Target { get @@ -88,7 +96,6 @@ public BindingTarget Target /// /// Gets or sets a value indicating whether the binding was implicitly registered. /// - /// public bool IsImplicit { get @@ -105,7 +112,6 @@ public bool IsImplicit /// /// Gets a value indicating whether the binding has a condition associated with it. /// - /// public bool IsConditional { get @@ -117,13 +123,13 @@ public bool IsConditional /// /// Gets or sets the condition defined for the binding. /// - /// public Func Condition { get { return this.BindingConfiguration.Condition; } + set { this.BindingConfiguration.Condition = value; @@ -133,7 +139,6 @@ public bool IsConditional /// /// Gets or sets the callback that returns the provider that should be used by the binding. /// - /// public Func ProviderCallback { get @@ -150,13 +155,13 @@ public bool IsConditional /// /// Gets or sets the callback that returns the object that will act as the binding's scope. /// - /// public Func ScopeCallback { get { return this.BindingConfiguration.ScopeCallback; } + set { this.BindingConfiguration.ScopeCallback = value; @@ -166,7 +171,6 @@ public bool IsConditional /// /// Gets the parameters defined for the binding. /// - /// public ICollection Parameters { get @@ -178,7 +182,6 @@ public ICollection Parameters /// /// Gets the actions that should be called after instances are activated via the binding. /// - /// public ICollection> ActivationActions { get @@ -190,7 +193,6 @@ public ICollection Parameters /// /// Gets the actions that should be called before instances are deactivated via the binding. /// - /// public ICollection> DeactivationActions { get @@ -199,6 +201,22 @@ public ICollection Parameters } } + /// + /// Gets or sets the InitizalizeProviderCallback action + /// + public Action InitializeProviderCallback + { + get + { + return this.BindingConfiguration.InitializeProviderCallback; + } + + set + { + this.BindingConfiguration.InitializeProviderCallback = value; + } + } + /// /// Gets the provider for the binding. /// @@ -233,21 +251,5 @@ public bool Matches(IRequest request) { return this.BindingConfiguration.Matches(request); } - - /// - /// Gets or sets the InitizalizeProviderCallback action - /// - public Action InitializeProviderCallback - { - get - { - return this.BindingConfiguration.InitializeProviderCallback; - } - - set - { - this.BindingConfiguration.InitializeProviderCallback = value; - } - } } } \ No newline at end of file diff --git a/src/Ninject/Planning/Bindings/BindingBuilder.cs b/src/Ninject/Planning/Bindings/BindingBuilder.cs index e4892c8b..7c5ac46b 100644 --- a/src/Ninject/Planning/Bindings/BindingBuilder.cs +++ b/src/Ninject/Planning/Bindings/BindingBuilder.cs @@ -1,10 +1,11 @@ //------------------------------------------------------------------------------- +//------------------------------------------------------------------------------------------------- // -// 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 @@ -83,7 +84,7 @@ protected IBindingWhenInNamedWithOrOnSyntax InternalTo(Type implementation return new BindingConfigurationBuilder(this.BindingConfiguration, this.ServiceNames); } - + /// /// Indicates that the service should be bound to the specified constant value. /// diff --git a/src/Ninject/Planning/Bindings/BindingBuilder{T1,T2,T3,T4}.cs b/src/Ninject/Planning/Bindings/BindingBuilder{T1,T2,T3,T4}.cs index fe7bc601..c520bc63 100644 --- a/src/Ninject/Planning/Bindings/BindingBuilder{T1,T2,T3,T4}.cs +++ b/src/Ninject/Planning/Bindings/BindingBuilder{T1,T2,T3,T4}.cs @@ -1,10 +1,11 @@ //------------------------------------------------------------------------------- +//------------------------------------------------------------------------------------------------- // -// 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 @@ -103,8 +104,8 @@ public IBindingWhenInNamedWithOrOnSyntax ToProvider() /// The type of provider to activate. /// The type of the implementation. /// The fluent syntax. - public IBindingWhenInNamedWithOrOnSyntax ToProvider() - where TProvider : IProvider + public IBindingWhenInNamedWithOrOnSyntax ToProvider() + where TProvider : IProvider where TImplementation : T1, T2, T3, T4 { return this.ToProviderInternal(); diff --git a/src/Ninject/Planning/Bindings/BindingBuilder{T1,T2,T3}.cs b/src/Ninject/Planning/Bindings/BindingBuilder{T1,T2,T3}.cs index c79633b5..689638b6 100644 --- a/src/Ninject/Planning/Bindings/BindingBuilder{T1,T2,T3}.cs +++ b/src/Ninject/Planning/Bindings/BindingBuilder{T1,T2,T3}.cs @@ -1,10 +1,11 @@ //------------------------------------------------------------------------------- +//------------------------------------------------------------------------------------------------- // -// 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 @@ -102,13 +103,13 @@ public IBindingWhenInNamedWithOrOnSyntax ToProvider() /// The type of provider to activate. /// The type of the implementation. /// The fluent syntax. - public IBindingWhenInNamedWithOrOnSyntax ToProvider() - where TProvider : IProvider + public IBindingWhenInNamedWithOrOnSyntax ToProvider() + where TProvider : IProvider where TImplementation : T1, T2, T3 { return this.ToProviderInternal(); } - + /// /// Indicates that the service should be bound to an instance of the specified provider type. /// The instance will be activated via the kernel when an instance of the service is activated. diff --git a/src/Ninject/Planning/Bindings/BindingBuilder{T1,T2}.cs b/src/Ninject/Planning/Bindings/BindingBuilder{T1,T2}.cs index bda8a3fa..4d59c507 100644 --- a/src/Ninject/Planning/Bindings/BindingBuilder{T1,T2}.cs +++ b/src/Ninject/Planning/Bindings/BindingBuilder{T1,T2}.cs @@ -1,10 +1,11 @@ //------------------------------------------------------------------------------- +//------------------------------------------------------------------------------------------------- // -// 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 @@ -101,13 +102,13 @@ public IBindingWhenInNamedWithOrOnSyntax ToProvider() /// The type of provider to activate. /// The type of the implementation. /// The fluent syntax. - public IBindingWhenInNamedWithOrOnSyntax ToProvider() - where TProvider : IProvider + public IBindingWhenInNamedWithOrOnSyntax ToProvider() + where TProvider : IProvider where TImplementation : T1, T2 { return this.ToProviderInternal(); } - + /// /// Indicates that the service should be bound to an instance of the specified provider type. /// The instance will be activated via the kernel when an instance of the service is activated. diff --git a/src/Ninject/Planning/Bindings/BindingBuilder{T1}.cs b/src/Ninject/Planning/Bindings/BindingBuilder{T1}.cs index 1b1f41f0..3f9b70e4 100644 --- a/src/Ninject/Planning/Bindings/BindingBuilder{T1}.cs +++ b/src/Ninject/Planning/Bindings/BindingBuilder{T1}.cs @@ -1,10 +1,11 @@ //------------------------------------------------------------------------------- +//------------------------------------------------------------------------------------------------- // -// 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 @@ -27,7 +28,6 @@ namespace Ninject.Planning.Bindings using System.Linq.Expressions; using Ninject.Activation; using Ninject.Activation.Providers; - using Ninject.Infrastructure; using Ninject.Syntax; /// @@ -54,7 +54,7 @@ public BindingBuilder(IBinding binding, INinjectSettings settings, string servic /// Gets the binding being built. /// public IBinding Binding { get; private set; } - + /// /// Indicates that the service should be self-bound. /// diff --git a/src/Ninject/Planning/Bindings/BindingConfiguration.cs b/src/Ninject/Planning/Bindings/BindingConfiguration.cs index 94f5a4ff..c84267bc 100644 --- a/src/Ninject/Planning/Bindings/BindingConfiguration.cs +++ b/src/Ninject/Planning/Bindings/BindingConfiguration.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 @@ -99,6 +102,11 @@ public bool IsConditional /// public ICollection> DeactivationActions { get; private set; } + /// + /// Gets or sets the InitizalizeProviderCallback action + /// + public Action InitializeProviderCallback { get; set; } + /// /// Gets the provider for the binding. /// @@ -128,10 +136,5 @@ public bool Matches(IRequest request) { return this.Condition == null || this.Condition(request); } - - /// - /// Gets or sets the InitizalizeProviderCallback action - /// - public Action InitializeProviderCallback { get; set; } } } \ No newline at end of file diff --git a/src/Ninject/Planning/Bindings/BindingConfigurationBuilder.cs b/src/Ninject/Planning/Bindings/BindingConfigurationBuilder.cs index b435b848..8b3f7855 100644 --- a/src/Ninject/Planning/Bindings/BindingConfigurationBuilder.cs +++ b/src/Ninject/Planning/Bindings/BindingConfigurationBuilder.cs @@ -1,10 +1,11 @@ //------------------------------------------------------------------------------- +//------------------------------------------------------------------------------------------------- // -// 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 @@ -26,7 +27,6 @@ namespace Ninject.Planning.Bindings using System; using System.Linq; - using System.Reflection; using Ninject.Activation; using Ninject.Infrastructure; @@ -47,13 +47,8 @@ public class BindingConfigurationBuilder : IBindingConfigurationSyntax /// private readonly string serviceNames; - /// - /// Gets the binding being built. - /// - public IBindingConfiguration BindingConfiguration { get; private set; } - - /// - /// Initializes a new instance of the BindingBuilder<T> class. + /// + /// Initializes a new instance of the class. /// /// The binding configuration to build. /// The names of the configured services. @@ -63,6 +58,11 @@ public BindingConfigurationBuilder(IBindingConfiguration bindingConfiguration, s this.serviceNames = serviceNames; } + /// + /// Gets the binding being built. + /// + public IBindingConfiguration BindingConfiguration { get; private set; } + /// /// Indicates that the binding should be used only for requests that support the specified condition. /// @@ -82,7 +82,7 @@ public IBindingInNamedWithOrOnSyntax When(Func condition) /// The fluent syntax. public IBindingInNamedWithOrOnSyntax WhenInjectedInto() { - return WhenInjectedInto(typeof(TParent)); + return this.WhenInjectedInto(typeof(TParent)); } /// @@ -93,10 +93,9 @@ public IBindingInNamedWithOrOnSyntax WhenInjectedInto() /// The fluent syntax. public IBindingInNamedWithOrOnSyntax WhenInjectedInto(Type parent) { - if (parent.GetTypeInfo().IsGenericTypeDefinition) { - if(parent.GetTypeInfo().IsInterface) + if (parent.GetTypeInfo().IsInterface) { this.BindingConfiguration.Condition = r => r.Target != null && @@ -106,7 +105,6 @@ public IBindingInNamedWithOrOnSyntax WhenInjectedInto(Type parent) } else { - this.BindingConfiguration.Condition = r => r.Target != null && r.Target.Member.DeclaringType.GetAllBaseTypes().Any(i => @@ -134,13 +132,11 @@ public IBindingInNamedWithOrOnSyntax WhenInjectedInto(params Type[] parents) { foreach (var parent in parents) { - bool matches = false; + var matches = false; if (parent.GetTypeInfo().IsGenericTypeDefinition) - { if (parent.GetTypeInfo().IsInterface) - { matches = r.Target != null && @@ -162,7 +158,10 @@ public IBindingInNamedWithOrOnSyntax WhenInjectedInto(params Type[] parents) matches = r.Target != null && parent.GetTypeInfo().IsAssignableFrom(r.Target.Member.DeclaringType.GetTypeInfo()); } - if (matches) return true; + if (matches) + { + return true; + } } return false; @@ -174,19 +173,19 @@ public IBindingInNamedWithOrOnSyntax WhenInjectedInto(params Type[] parents) /// /// Indicates that the binding should be used only for injections on the specified type. /// The type must match exactly the specified type. Types that derive from the specified type - /// will not be considered as valid target. + /// will not be considered as valid target. /// /// The type. /// The fluent syntax. public IBindingInNamedWithOrOnSyntax WhenInjectedExactlyInto() { - return WhenInjectedExactlyInto(typeof(TParent)); + return this.WhenInjectedExactlyInto(typeof(TParent)); } /// /// Indicates that the binding should be used only for injections on the specified type. /// The type must match exactly the specified type. Types that derive from the specified type - /// will not be considered as valid target. + /// will not be considered as valid target. /// /// The type. /// The fluent syntax. @@ -210,20 +209,20 @@ public IBindingInNamedWithOrOnSyntax WhenInjectedExactlyInto(Type parent) /// /// Indicates that the binding should be used only for injections on the specified type. /// The type must match exactly the specified type. Types that derive from the specified type - /// will not be considered as valid target. + /// will not be considered as valid target. /// Should match at least one of the specified targets /// /// The types. /// The fluent syntax. public IBindingInNamedWithOrOnSyntax WhenInjectedExactlyInto(params Type[] parents) { - this.BindingConfiguration.Condition = r => { + this.BindingConfiguration.Condition = r => + { foreach (var parent in parents) { - bool matches = false; - - if(parent.GetTypeInfo().IsGenericTypeDefinition) + var matches = false; + if (parent.GetTypeInfo().IsGenericTypeDefinition) { matches = r.Target != null && @@ -235,7 +234,10 @@ public IBindingInNamedWithOrOnSyntax WhenInjectedExactlyInto(params Type[] pa matches = r.Target != null && r.Target.Member.DeclaringType == parent; } - if(matches) return true; + if (matches) + { + return true; + } } return false; @@ -250,9 +252,10 @@ public IBindingInNamedWithOrOnSyntax WhenInjectedExactlyInto(params Type[] pa /// /// The type of attribute. /// The fluent syntax. - public IBindingInNamedWithOrOnSyntax WhenClassHas() where TAttribute : Attribute + public IBindingInNamedWithOrOnSyntax WhenClassHas() + where TAttribute : Attribute { - return WhenClassHas(typeof(TAttribute)); + return this.WhenClassHas(typeof(TAttribute)); } /// @@ -261,9 +264,10 @@ public IBindingInNamedWithOrOnSyntax WhenInjectedExactlyInto(params Type[] pa /// /// The type of attribute. /// The fluent syntax. - public IBindingInNamedWithOrOnSyntax WhenMemberHas() where TAttribute : Attribute + public IBindingInNamedWithOrOnSyntax WhenMemberHas() + where TAttribute : Attribute { - return WhenMemberHas(typeof(TAttribute)); + return this.WhenMemberHas(typeof(TAttribute)); } /// @@ -272,9 +276,10 @@ public IBindingInNamedWithOrOnSyntax WhenInjectedExactlyInto(params Type[] pa /// /// The type of attribute. /// The fluent syntax. - public IBindingInNamedWithOrOnSyntax WhenTargetHas() where TAttribute : Attribute + public IBindingInNamedWithOrOnSyntax WhenTargetHas() + where TAttribute : Attribute { - return WhenTargetHas(typeof(TAttribute)); + return this.WhenTargetHas(typeof(TAttribute)); } /// @@ -285,8 +290,7 @@ public IBindingInNamedWithOrOnSyntax WhenInjectedExactlyInto(params Type[] pa /// The fluent syntax. public IBindingInNamedWithOrOnSyntax WhenClassHas(Type attributeType) { - - if(!typeof(Attribute).GetTypeInfo().IsAssignableFrom(attributeType.GetTypeInfo())) + if (!typeof(Attribute).GetTypeInfo().IsAssignableFrom(attributeType.GetTypeInfo())) { throw new InvalidOperationException(ExceptionFormatter.InvalidAttributeTypeUsedInBindingCondition(this.serviceNames, "WhenClassHas", attributeType)); } @@ -305,11 +309,11 @@ public IBindingInNamedWithOrOnSyntax WhenClassHas(Type attributeType) /// The fluent syntax. public IBindingInNamedWithOrOnSyntax WhenMemberHas(Type attributeType) { - if(!typeof(Attribute).GetTypeInfo().IsAssignableFrom(attributeType.GetTypeInfo())) + if (!typeof(Attribute).GetTypeInfo().IsAssignableFrom(attributeType.GetTypeInfo())) { throw new InvalidOperationException(ExceptionFormatter.InvalidAttributeTypeUsedInBindingCondition(this.serviceNames, "WhenMemberHas", attributeType)); } - + this.BindingConfiguration.Condition = r => r.Target != null && r.Target.Member.IsDefined(attributeType, true); return this; @@ -325,10 +329,10 @@ public IBindingInNamedWithOrOnSyntax WhenTargetHas(Type attributeType) { if (!typeof(Attribute).GetTypeInfo().IsAssignableFrom(attributeType.GetTypeInfo())) { - throw new InvalidOperationException(ExceptionFormatter.InvalidAttributeTypeUsedInBindingCondition(this.serviceNames, "WhenTargetHas", attributeType)); + throw new InvalidOperationException(ExceptionFormatter.InvalidAttributeTypeUsedInBindingCondition(this.serviceNames, "WhenTargetHas", attributeType)); } - this.BindingConfiguration.Condition = r => r.Target != null && r.Target.IsDefined(attributeType, true); + this.BindingConfiguration.Condition = r => r.Target != null && r.Target.HasAttribute(attributeType); return this; } @@ -432,7 +436,7 @@ public IBindingNamedWithOrOnSyntax InTransientScope() return this; } -#if !NETSTANDARD1_3 && !WINRT +#if !CORE /// /// Indicates that instances activated via the binding should be re-used within the same thread. /// @@ -540,7 +544,7 @@ public IBindingWithOrOnSyntax WithConstructorArgument(Func /// The type of the argument to override. - /// The callback to invoke to get the value for the argument. + /// The callback to invoke to get the value for the argument. /// The fluent syntax. public IBindingWithOrOnSyntax WithConstructorArgument(Type type, Func callback) { @@ -552,11 +556,11 @@ public IBindingWithOrOnSyntax WithConstructorArgument(Type type, Func /// Specifies the argument type to override. - /// The callback to invoke to get the value for the argument. + /// The callback to invoke to get the value for the argument. /// The fluent syntax. public IBindingWithOrOnSyntax WithConstructorArgument(Func callback) { - this.WithConstructorArgument(typeof (TValue), callback); + this.WithConstructorArgument(typeof(TValue), callback); return this; } @@ -595,7 +599,7 @@ public IBindingWithOrOnSyntax WithPropertyValue(string name, Func /// Adds a custom parameter to the binding. /// @@ -720,4 +724,4 @@ private static bool DoesAnyAncestorMatch(IRequest request, Predicate p DoesAnyAncestorMatch(parentContext.Request, predicate); } } -} +} \ No newline at end of file diff --git a/src/Ninject/Planning/Bindings/BindingMetadata.cs b/src/Ninject/Planning/Bindings/BindingMetadata.cs index ed0b16bc..68f9bbd1 100644 --- a/src/Ninject/Planning/Bindings/BindingMetadata.cs +++ b/src/Ninject/Planning/Bindings/BindingMetadata.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 System.Collections.Generic; -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.Planning.Bindings { + using System.Collections.Generic; + /// /// Additional information available about a binding, which can be used in constraints /// to select bindings to use in activation. @@ -46,12 +56,13 @@ public bool Has(string key) /// The metadata value. public T Get(string key) { - return Get(key, default(T)); + return this.Get(key, default(T)); } /// /// Gets the value of metadata defined with the specified key. /// + /// The type of value to expect. /// The metadata key. /// The value to return if the binding has no metadata set with the specified key. /// The metadata value, or the default value if none was set. diff --git a/src/Ninject/Planning/Bindings/BindingTarget.cs b/src/Ninject/Planning/Bindings/BindingTarget.cs index 7e2d9792..fc63e90e 100644 --- a/src/Ninject/Planning/Bindings/BindingTarget.cs +++ b/src/Ninject/Planning/Bindings/BindingTarget.cs @@ -1,18 +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 System.Collections.Generic; -using Ninject.Activation; -using Ninject.Parameters; -#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.Planning.Bindings { diff --git a/src/Ninject/Planning/Bindings/IBinding.cs b/src/Ninject/Planning/Bindings/IBinding.cs index 2b3d009a..6bc14998 100644 --- a/src/Ninject/Planning/Bindings/IBinding.cs +++ b/src/Ninject/Planning/Bindings/IBinding.cs @@ -1,21 +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 System.Collections.Generic; -using Ninject.Activation; -using Ninject.Parameters; -#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.Planning.Bindings { + using System; + /// /// Contains information about a service registration. /// diff --git a/src/Ninject/Planning/Bindings/IBindingConfiguration.cs b/src/Ninject/Planning/Bindings/IBindingConfiguration.cs index 55ae3430..6c919eda 100644 --- a/src/Ninject/Planning/Bindings/IBindingConfiguration.cs +++ b/src/Ninject/Planning/Bindings/IBindingConfiguration.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 @@ -82,6 +85,11 @@ public interface IBindingConfiguration /// ICollection> DeactivationActions { get; } + /// + /// Gets or sets the InitizalizeProviderCallback action + /// + Action InitializeProviderCallback { get; set; } + /// /// Gets the provider for the binding. /// @@ -103,10 +111,5 @@ public interface IBindingConfiguration /// The request. /// True if the request satisfies the condition; otherwise false. bool Matches(IRequest request); - - /// - /// Gets or sets the InitizalizeProviderCallback action - /// - Action InitializeProviderCallback { get; set; } } } \ No newline at end of file diff --git a/src/Ninject/Planning/Bindings/IBindingConfigurationSyntax.cs b/src/Ninject/Planning/Bindings/IBindingConfigurationSyntax.cs new file mode 100644 index 00000000..ddb32796 --- /dev/null +++ b/src/Ninject/Planning/Bindings/IBindingConfigurationSyntax.cs @@ -0,0 +1,39 @@ +//------------------------------------------------------------------------------------------------- +// +// 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.Planning.Bindings +{ + using Ninject.Syntax; + + /// + /// The syntax to define bindings. + /// + /// The type of the service. + public interface IBindingConfigurationSyntax : + IBindingWhenInNamedWithOrOnSyntax, + IBindingInNamedWithOrOnSyntax, + IBindingNamedWithOrOnSyntax, + IBindingWithOrOnSyntax + { + } +} \ No newline at end of file diff --git a/src/Ninject/Planning/Bindings/IBindingMetadata.cs b/src/Ninject/Planning/Bindings/IBindingMetadata.cs index 5e1e77e7..e705c34d 100644 --- a/src/Ninject/Planning/Bindings/IBindingMetadata.cs +++ b/src/Ninject/Planning/Bindings/IBindingMetadata.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.Planning.Bindings { @@ -42,6 +52,7 @@ public interface IBindingMetadata /// /// Gets the value of metadata defined with the specified key. /// + /// The type of value to expect. /// The metadata key. /// The value to return if the binding has no metadata set with the specified key. /// The metadata value, or the default value if none was set. diff --git a/src/Ninject/Planning/Bindings/IBindingSyntax.cs b/src/Ninject/Planning/Bindings/IBindingSyntax.cs deleted file mode 100644 index e7474e5c..00000000 --- a/src/Ninject/Planning/Bindings/IBindingSyntax.cs +++ /dev/null @@ -1,24 +0,0 @@ -// -// 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. -// - -namespace Ninject.Planning.Bindings -{ - using Ninject.Syntax; - - /// - /// The syntax to define bindings. - /// - /// The type of the service. - public interface IBindingConfigurationSyntax : - IBindingWhenInNamedWithOrOnSyntax, - IBindingInNamedWithOrOnSyntax, - IBindingNamedWithOrOnSyntax, - IBindingWithOrOnSyntax - { - } -} \ No newline at end of file diff --git a/src/Ninject/Planning/Bindings/Resolvers/DefaultValueBindingResolver.cs b/src/Ninject/Planning/Bindings/Resolvers/DefaultValueBindingResolver.cs index f7493ad8..250de457 100644 --- a/src/Ninject/Planning/Bindings/Resolvers/DefaultValueBindingResolver.cs +++ b/src/Ninject/Planning/Bindings/Resolvers/DefaultValueBindingResolver.cs @@ -1,29 +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; -using System.Linq; -using Ninject.Activation; -using Ninject.Components; -using Ninject.Infrastructure; -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.Planning.Bindings.Resolvers { + using System; + using System.Collections.Generic; + using System.Linq; + using Ninject.Activation; + using Ninject.Components; + using Ninject.Planning.Targets; - /// - /// + /// + /// Represents a binding resolver that takes the target default value as the resolved object. + /// public class DefaultValueBindingResolver : NinjectComponent, IMissingBindingResolver { /// @@ -56,7 +65,7 @@ private class DefaultParameterValueProvider : IProvider { public DefaultParameterValueProvider(Type type) { - Type = type; + this.Type = type; } public Type Type { get; private set; } diff --git a/src/Ninject/Planning/Bindings/Resolvers/IBindingResolver.cs b/src/Ninject/Planning/Bindings/Resolvers/IBindingResolver.cs index 3e248b0c..50d394fe 100644 --- a/src/Ninject/Planning/Bindings/Resolvers/IBindingResolver.cs +++ b/src/Ninject/Planning/Bindings/Resolvers/IBindingResolver.cs @@ -1,23 +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; -using Ninject.Components; -using Ninject.Infrastructure; -using Ninject.Parameters; -#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.Planning.Bindings.Resolvers { + using System; + using System.Collections.Generic; + using Ninject.Components; + /// /// Contains logic about which bindings to use for a given service request. /// diff --git a/src/Ninject/Planning/Bindings/Resolvers/IMissingBindingResolver.cs b/src/Ninject/Planning/Bindings/Resolvers/IMissingBindingResolver.cs index a35e90c0..08998ecf 100644 --- a/src/Ninject/Planning/Bindings/Resolvers/IMissingBindingResolver.cs +++ b/src/Ninject/Planning/Bindings/Resolvers/IMissingBindingResolver.cs @@ -1,28 +1,37 @@ -#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; -using Ninject.Components; -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.Planning.Bindings.Resolvers { - /// + using System; + using System.Collections.Generic; + using Ninject.Activation; + using Ninject.Components; + + /// /// Contains logic about which bindings to use for a given service request /// when other attempts have failed. - /// + /// public interface IMissingBindingResolver : INinjectComponent { /// diff --git a/src/Ninject/Planning/Bindings/Resolvers/OpenGenericBindingResolver.cs b/src/Ninject/Planning/Bindings/Resolvers/OpenGenericBindingResolver.cs index b6a6d252..fbcea404 100644 --- a/src/Ninject/Planning/Bindings/Resolvers/OpenGenericBindingResolver.cs +++ b/src/Ninject/Planning/Bindings/Resolvers/OpenGenericBindingResolver.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 System.Linq; -using Ninject.Components; -using Ninject.Infrastructure; -using Ninject.Infrastructure.Language; -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.Planning.Bindings.Resolvers { + using System; + using System.Collections.Generic; + using System.Linq; + using System.Reflection; + using Ninject.Components; + /// /// Resolves bindings for open generic types. /// @@ -33,7 +43,9 @@ public class OpenGenericBindingResolver : NinjectComponent, IBindingResolver public IEnumerable Resolve(IDictionary> bindings, Type service) { if (!service.GetTypeInfo().IsGenericType || service.GetTypeInfo().IsGenericTypeDefinition || !bindings.ContainsKey(service.GetGenericTypeDefinition())) + { return Enumerable.Empty(); + } return bindings[service.GetGenericTypeDefinition()]; } diff --git a/src/Ninject/Planning/Bindings/Resolvers/SelfBindingResolver.cs b/src/Ninject/Planning/Bindings/Resolvers/SelfBindingResolver.cs index a45bc0e8..37d8a5e8 100644 --- a/src/Ninject/Planning/Bindings/Resolvers/SelfBindingResolver.cs +++ b/src/Ninject/Planning/Bindings/Resolvers/SelfBindingResolver.cs @@ -1,37 +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 -#region Using Directives - -using System; -using System.Collections.Generic; -using System.Linq; -using System.Reflection; -using Ninject.Activation; -using Ninject.Activation.Providers; -using Ninject.Components; -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.Planning.Bindings.Resolvers { + using System; + using System.Collections.Generic; + using System.Linq; + using System.Reflection; + using Ninject.Activation; + using Ninject.Activation.Providers; + using Ninject.Components; using Ninject.Selection; - /// - /// + /// + /// Represents a binding resolver that use the service in question itself as the target to activate. + /// public class SelfBindingResolver : NinjectComponent, IMissingBindingResolver { private readonly ISelector selector; /// - /// Initializes a new instance of the class. + /// Initializes a new instance of the class. /// /// Dependency injection for public SelfBindingResolver(ISelector selector) @@ -48,15 +57,16 @@ public SelfBindingResolver(ISelector selector) public IEnumerable Resolve(IDictionary> bindings, IRequest request) { var service = request.Service; - if (!TypeIsSelfBindable(service)) + if (!this.TypeIsSelfBindable(service)) { return Enumerable.Empty(); } + return new[] { new Binding(service) { - ProviderCallback = StandardProvider.GetCreationCallback(service, selector) + ProviderCallback = StandardProvider.GetCreationCallback(service, this.selector) } }; } diff --git a/src/Ninject/Planning/Bindings/Resolvers/StandardBindingResolver.cs b/src/Ninject/Planning/Bindings/Resolvers/StandardBindingResolver.cs index 85f0a84f..3943d6c9 100644 --- a/src/Ninject/Planning/Bindings/Resolvers/StandardBindingResolver.cs +++ b/src/Ninject/Planning/Bindings/Resolvers/StandardBindingResolver.cs @@ -1,24 +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.Components; -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.Planning.Bindings.Resolvers { + using System; + using System.Collections.Generic; using System.Linq; + using Ninject.Components; /// /// Resolves bindings that have been registered directly for the service. @@ -34,8 +42,8 @@ public class StandardBindingResolver : NinjectComponent, IBindingResolver public IEnumerable Resolve(IDictionary> bindings, Type service) { IEnumerable result; - return bindings.TryGetValue(service, out result) - ? result + return bindings.TryGetValue(service, out result) + ? result : Enumerable.Empty(); } } diff --git a/src/Ninject/Planning/Directives/ConstructorInjectionDirective.cs b/src/Ninject/Planning/Directives/ConstructorInjectionDirective.cs index 472b7790..520b6994 100644 --- a/src/Ninject/Planning/Directives/ConstructorInjectionDirective.cs +++ b/src/Ninject/Planning/Directives/ConstructorInjectionDirective.cs @@ -1,46 +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 -#region Using Directives -using System; -using System.Reflection; -using Ninject.Infrastructure; -using Ninject.Injection; -#endregion - -namespace Ninject.Planning.Directives -{ - /// - /// Describes the injection of a constructor. - /// - public class ConstructorInjectionDirective : MethodInjectionDirectiveBase +//------------------------------------------------------------------------------------------------- +// +// 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.Planning.Directives +{ + using System.Reflection; + using Ninject.Injection; + + /// + /// Describes the injection of a constructor. + /// + public class ConstructorInjectionDirective : MethodInjectionDirectiveBase { - /// - /// The base .ctor definition. - /// + /// + /// Initializes a new instance of the class. + /// + /// The constructor described by the directive. + /// The injector that will be triggered. + public ConstructorInjectionDirective(ConstructorInfo constructor, ConstructorInjector injector) + : base(constructor, injector) + { + this.Constructor = constructor; + } + + /// + /// Gets or sets the base .ctor definition. + /// public ConstructorInfo Constructor { get; set; } - /// - /// Gets or sets a value indicating whether this constructor has an inject attribute. - /// - /// true if this constructor has an inject attribute; otherwise, false. - public bool HasInjectAttribute { get; set; } - - /// - /// Initializes a new instance of the class. - /// - /// The constructor described by the directive. - /// The injector that will be triggered. - public ConstructorInjectionDirective(ConstructorInfo constructor, ConstructorInjector injector) - : base(constructor, injector) - { - Constructor = constructor; - } - } + /// + /// Gets or sets a value indicating whether this constructor has an inject attribute. + /// + /// true if this constructor has an inject attribute; otherwise, false. + public bool HasInjectAttribute { get; set; } + } } \ No newline at end of file diff --git a/src/Ninject/Planning/Directives/IDirective.cs b/src/Ninject/Planning/Directives/IDirective.cs index d430579a..feb7ab4c 100644 --- a/src/Ninject/Planning/Directives/IDirective.cs +++ b/src/Ninject/Planning/Directives/IDirective.cs @@ -1,20 +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; -#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.Planning.Directives { /// /// A piece of information used in an . (Just a marker.) /// - public interface IDirective { } + public interface IDirective + { + } } \ No newline at end of file diff --git a/src/Ninject/Planning/Directives/MethodInjectionDirective.cs b/src/Ninject/Planning/Directives/MethodInjectionDirective.cs index 15b589c4..c252d0a9 100644 --- a/src/Ninject/Planning/Directives/MethodInjectionDirective.cs +++ b/src/Ninject/Planning/Directives/MethodInjectionDirective.cs @@ -1,21 +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.Infrastructure; -using Ninject.Injection; -#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.Planning.Directives { + using System.Reflection; + using Ninject.Injection; + /// /// Describes the injection of a method. /// @@ -27,6 +37,8 @@ public class MethodInjectionDirective : MethodInjectionDirectiveBaseThe method described by the directive. /// The injector that will be triggered. public MethodInjectionDirective(MethodInfo method, MethodInjector injector) - : base(method, injector) { } + : base(method, injector) + { + } } } \ No newline at end of file diff --git a/src/Ninject/Planning/Directives/MethodInjectionDirectiveBase.cs b/src/Ninject/Planning/Directives/MethodInjectionDirectiveBase.cs index 4965cc0c..24c485d8 100644 --- a/src/Ninject/Planning/Directives/MethodInjectionDirectiveBase.cs +++ b/src/Ninject/Planning/Directives/MethodInjectionDirectiveBase.cs @@ -1,49 +1,61 @@ -#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 System.Reflection; -using Ninject.Infrastructure; -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.Planning.Directives { + using System.Linq; + using System.Reflection; + using Ninject.Planning.Targets; + /// /// Describes the injection of a method or constructor. /// + /// The method info. + /// The injector. public abstract class MethodInjectionDirectiveBase : IDirective where TMethod : MethodBase { /// - /// Gets or sets the injector that will be triggered. - /// - public TInjector Injector { get; private set; } - - /// - /// Gets or sets the targets for the directive. - /// - public ITarget[] Targets { get; private set; } - - /// - /// Initializes a new instance of the MethodInjectionDirectiveBase<TMethod, TInjector> class. + /// Initializes a new instance of the class. /// /// The method this directive represents. /// The injector that will be triggered. protected MethodInjectionDirectiveBase(TMethod method, TInjector injector) { this.Injector = injector; - this.Targets = CreateTargetsFromParameters(method); + this.Targets = this.CreateTargetsFromParameters(method); } + /// + /// Gets the injector that will be triggered. + /// + public TInjector Injector { get; private set; } + + /// + /// Gets the targets for the directive. + /// + public ITarget[] Targets { get; private set; } + /// /// Creates targets for the parameters of the method. /// @@ -54,4 +66,4 @@ protected virtual ITarget[] CreateTargetsFromParameters(TMethod method) return method.GetParameters().Select(parameter => new ParameterTarget(method, parameter)).ToArray(); } } -} +} \ No newline at end of file diff --git a/src/Ninject/Planning/Directives/PropertyInjectionDirective.cs b/src/Ninject/Planning/Directives/PropertyInjectionDirective.cs index 1642dafc..d1afe37e 100644 --- a/src/Ninject/Planning/Directives/PropertyInjectionDirective.cs +++ b/src/Ninject/Planning/Directives/PropertyInjectionDirective.cs @@ -1,36 +1,37 @@ -#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.Injection; -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.Planning.Directives { + using System.Reflection; + using Ninject.Injection; + using Ninject.Planning.Targets; + /// /// Describes the injection of a property. /// public class PropertyInjectionDirective : IDirective { - /// - /// Gets or sets the injector that will be triggered. - /// - public PropertyInjector Injector { get; private set; } - - /// - /// Gets or sets the injection target for the directive. - /// - public ITarget Target { get; private set; } - /// /// Initializes a new instance of the class. /// @@ -38,10 +39,20 @@ public class PropertyInjectionDirective : IDirective /// The injector that will be triggered. public PropertyInjectionDirective(PropertyInfo member, PropertyInjector injector) { - Injector = injector; - Target = CreateTarget(member); + this.Injector = injector; + this.Target = this.CreateTarget(member); } + /// + /// Gets the injector that will be triggered. + /// + public PropertyInjector Injector { get; private set; } + + /// + /// Gets the injection target for the directive. + /// + public ITarget Target { get; private set; } + /// /// Creates a target for the property. /// @@ -52,4 +63,4 @@ protected virtual ITarget CreateTarget(PropertyInfo propertyInfo) return new PropertyTarget(propertyInfo); } } -} +} \ No newline at end of file diff --git a/src/Ninject/Planning/IPlan.cs b/src/Ninject/Planning/IPlan.cs index 606dd4c0..57e1c458 100644 --- a/src/Ninject/Planning/IPlan.cs +++ b/src/Ninject/Planning/IPlan.cs @@ -1,20 +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.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.Planning { + using System; + using System.Collections.Generic; + using Ninject.Planning.Directives; + /// /// Describes the means by which a type should be activated. /// @@ -42,20 +54,23 @@ public interface IPlan /// /// The type of directive. /// True if the plan has one or more directives of the type; otherwise, false. - bool Has() where TDirective : IDirective; + bool Has() + where TDirective : IDirective; /// /// Gets the first directive of the specified type from the plan. /// /// The type of directive. /// The first directive, or if no matching directives exist. - TDirective GetOne() where TDirective : IDirective; + TDirective GetOne() + where TDirective : IDirective; /// /// Gets all directives of the specified type that exist in the plan. /// /// The type of directive. /// A series of directives of the specified type. - IEnumerable GetAll() where TDirective : IDirective; + IEnumerable GetAll() + where TDirective : IDirective; } } \ No newline at end of file diff --git a/src/Ninject/Planning/IPlanner.cs b/src/Ninject/Planning/IPlanner.cs index b7fd660a..a803943b 100644 --- a/src/Ninject/Planning/IPlanner.cs +++ b/src/Ninject/Planning/IPlanner.cs @@ -1,21 +1,33 @@ -#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.Components; -using Ninject.Planning.Strategies; -#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.Planning { + using System; + using System.Collections.Generic; + using Ninject.Components; + using Ninject.Planning.Strategies; + /// /// Generates plans for how to activate instances. /// diff --git a/src/Ninject/Planning/Plan.cs b/src/Ninject/Planning/Plan.cs index 440b58b1..9f8be525 100644 --- a/src/Ninject/Planning/Plan.cs +++ b/src/Ninject/Planning/Plan.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. @@ -30,6 +34,17 @@ namespace Ninject.Planning /// public class Plan : IPlan { + /// + /// Initializes a new instance of the class. + /// + /// The type the plan describes. + public Plan(Type type) + { + this.Type = type; + this.Directives = new List(); + this.ConstructorInjectionDirectives = new List(); + } + /// /// Gets the type that the plan describes. /// @@ -45,17 +60,6 @@ public class Plan : IPlan /// public IList ConstructorInjectionDirectives { get; private set; } - /// - /// Initializes a new instance of the class. - /// - /// The type the plan describes. - public Plan(Type type) - { - Type = type; - this.Directives = new List(); - this.ConstructorInjectionDirectives = new List(); - } - /// /// Adds the specified directive to the plan. /// @@ -71,7 +75,7 @@ public void Add(IDirective directive) { this.Directives.Add(directive); } - } + } /// /// Determines whether the plan contains one or more directives of the specified type. diff --git a/src/Ninject/Planning/Planner.cs b/src/Ninject/Planning/Planner.cs index 49acebdc..3856c4d3 100644 --- a/src/Ninject/Planning/Planner.cs +++ b/src/Ninject/Planning/Planner.cs @@ -1,10 +1,11 @@ //------------------------------------------------------------------------------- +//------------------------------------------------------------------------------------------------- // -// 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 @@ -28,7 +29,6 @@ namespace Ninject.Planning using System.Linq; using System.Threading; using Ninject.Components; - using Ninject.Infrastructure; using Ninject.Infrastructure.Language; using Ninject.Planning.Strategies; @@ -37,8 +37,6 @@ namespace Ninject.Planning /// public class Planner : NinjectComponent, IPlanner { - - private readonly ReaderWriterLockSlim plannerLock = new ReaderWriterLockSlim(); private readonly Dictionary plans = new Dictionary(); @@ -56,7 +54,7 @@ public Planner(IEnumerable strategies) /// Gets the strategies that contribute to the planning process. /// public IList Strategies { get; private set; } - + /// /// Gets or creates an activation plan for the specified type. /// @@ -64,11 +62,6 @@ public Planner(IEnumerable strategies) /// The type's activation plan. public IPlan GetPlan(Type type) { -#if PCL - throw new NotImplementedException(); -#else - - this.plannerLock.EnterUpgradeableReadLock(); try @@ -78,11 +71,8 @@ public IPlan GetPlan(Type type) } finally { - this.plannerLock.ExitUpgradeableReadLock(); - } -#endif } /// @@ -103,10 +93,6 @@ protected virtual IPlan CreateEmptyPlan(Type type) /// The newly created plan. private IPlan CreateNewPlan(Type type) { -#if PCL - throw new NotImplementedException(); -#else - this.plannerLock.EnterWriteLock(); try @@ -125,11 +111,8 @@ private IPlan CreateNewPlan(Type type) } finally { - this.plannerLock.ExitWriteLock(); - } -#endif } } } \ No newline at end of file diff --git a/src/Ninject/Planning/Strategies/ConstructorReflectionStrategy.cs b/src/Ninject/Planning/Strategies/ConstructorReflectionStrategy.cs index 8217bb84..f20305ab 100644 --- a/src/Ninject/Planning/Strategies/ConstructorReflectionStrategy.cs +++ b/src/Ninject/Planning/Strategies/ConstructorReflectionStrategy.cs @@ -1,75 +1,84 @@ -#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.Reflection; -using Ninject.Components; -using Ninject.Infrastructure; -using Ninject.Infrastructure.Language; -using Ninject.Injection; -using Ninject.Planning.Directives; -using Ninject.Selection; -#endregion - -namespace Ninject.Planning.Strategies +//------------------------------------------------------------------------------------------------- +// +// 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.Planning.Strategies { + using System.Collections.Generic; + using System.Reflection; + using Ninject.Components; using Ninject.Infrastructure.Language; + using Ninject.Injection; + using Ninject.Planning.Directives; + using Ninject.Selection; + + /// + /// Adds a directive to plans indicating which constructor should be injected during activation. + /// + public class ConstructorReflectionStrategy : NinjectComponent, IPlanningStrategy + { + /// + /// Initializes a new instance of the class. + /// + /// The selector component. + /// The injector factory component. + public ConstructorReflectionStrategy(ISelector selector, IInjectorFactory injectorFactory) + { + this.Selector = selector; + this.InjectorFactory = injectorFactory; + } + + /// + /// Gets the selector component. + /// + public ISelector Selector { get; private set; } + + /// + /// Gets the injector factory component. + /// + public IInjectorFactory InjectorFactory { get; private set; } + + /// + /// Adds a to the plan for the constructor + /// that should be injected. + /// + /// The plan that is being generated. + public void Execute(IPlan plan) + { + var constructors = this.Selector.SelectConstructorsForInjection(plan.Type); + if (constructors == null) + { + return; + } - /// - /// Adds a directive to plans indicating which constructor should be injected during activation. - /// - public class ConstructorReflectionStrategy : NinjectComponent, IPlanningStrategy - { - /// - /// Gets the selector component. - /// - public ISelector Selector { get; private set; } - - /// - /// Gets the injector factory component. - /// - public IInjectorFactory InjectorFactory { get; set; } - - /// - /// Initializes a new instance of the class. - /// - /// The selector component. - /// The injector factory component. - public ConstructorReflectionStrategy(ISelector selector, IInjectorFactory injectorFactory) - { - this.Selector = selector; - this.InjectorFactory = injectorFactory; - } - - /// - /// Adds a to the plan for the constructor - /// that should be injected. - /// - /// The plan that is being generated. - public void Execute(IPlan plan) - { - IEnumerable constructors = Selector.SelectConstructorsForInjection(plan.Type); - if(constructors == null) - return; - - foreach(ConstructorInfo constructor in constructors) + foreach (ConstructorInfo constructor in constructors) { - var hasInjectAttribute = constructor.HasAttribute(Settings.InjectAttribute); - var directive = new ConstructorInjectionDirective(constructor, InjectorFactory.Create(constructor)) + var hasInjectAttribute = constructor.HasAttribute(this.Settings.InjectAttribute); + var directive = new ConstructorInjectionDirective(constructor, this.InjectorFactory.Create(constructor)) { HasInjectAttribute = hasInjectAttribute }; - plan.Add(directive); - } - } - } + plan.Add(directive); + } + } + } } \ No newline at end of file diff --git a/src/Ninject/Planning/Strategies/IPlanningStrategy.cs b/src/Ninject/Planning/Strategies/IPlanningStrategy.cs index a4b3da2b..9e6fd47c 100644 --- a/src/Ninject/Planning/Strategies/IPlanningStrategy.cs +++ b/src/Ninject/Planning/Strategies/IPlanningStrategy.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.Planning.Strategies { + using Ninject.Components; + /// /// Contributes to the generation of a . /// diff --git a/src/Ninject/Planning/Strategies/MethodReflectionStrategy.cs b/src/Ninject/Planning/Strategies/MethodReflectionStrategy.cs index 3b85ad46..b2939350 100644 --- a/src/Ninject/Planning/Strategies/MethodReflectionStrategy.cs +++ b/src/Ninject/Planning/Strategies/MethodReflectionStrategy.cs @@ -1,39 +1,39 @@ -#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; -using Ninject.Infrastructure; -using Ninject.Injection; -using Ninject.Planning.Directives; -using Ninject.Selection; -#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.Planning.Strategies { + using System.Reflection; + using Ninject.Components; + using Ninject.Injection; + using Ninject.Planning.Directives; + using Ninject.Selection; + /// /// Adds directives to plans indicating which methods should be injected during activation. /// public class MethodReflectionStrategy : NinjectComponent, IPlanningStrategy { - /// - /// Gets the selector component. - /// - public ISelector Selector { get; private set; } - - /// - /// Gets the injector factory component. - /// - public IInjectorFactory InjectorFactory { get; set; } - /// /// Initializes a new instance of the class. /// @@ -45,6 +45,16 @@ public MethodReflectionStrategy(ISelector selector, IInjectorFactory injectorFac this.InjectorFactory = injectorFactory; } + /// + /// Gets the selector component. + /// + public ISelector Selector { get; private set; } + + /// + /// Gets the injector factory component. + /// + public IInjectorFactory InjectorFactory { get; private set; } + /// /// Adds a to the plan for each method /// that should be injected. @@ -52,8 +62,10 @@ public MethodReflectionStrategy(ISelector selector, IInjectorFactory injectorFac /// The plan that is being generated. public void Execute(IPlan plan) { - foreach (MethodInfo method in Selector.SelectMethodsForInjection(plan.Type)) - plan.Add(new MethodInjectionDirective(method, InjectorFactory.Create(method))); + foreach (MethodInfo method in this.Selector.SelectMethodsForInjection(plan.Type)) + { + plan.Add(new MethodInjectionDirective(method, this.InjectorFactory.Create(method))); + } } } } \ No newline at end of file diff --git a/src/Ninject/Planning/Strategies/PropertyReflectionStrategy.cs b/src/Ninject/Planning/Strategies/PropertyReflectionStrategy.cs index d3840396..0db756c6 100644 --- a/src/Ninject/Planning/Strategies/PropertyReflectionStrategy.cs +++ b/src/Ninject/Planning/Strategies/PropertyReflectionStrategy.cs @@ -1,39 +1,39 @@ -#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; -using Ninject.Infrastructure; -using Ninject.Injection; -using Ninject.Planning.Directives; -using Ninject.Selection; -#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.Planning.Strategies { + using System.Reflection; + using Ninject.Components; + using Ninject.Injection; + using Ninject.Planning.Directives; + using Ninject.Selection; + /// /// Adds directives to plans indicating which properties should be injected during activation. /// public class PropertyReflectionStrategy : NinjectComponent, IPlanningStrategy { - /// - /// Gets the selector component. - /// - public ISelector Selector { get; private set; } - - /// - /// Gets the injector factory component. - /// - public IInjectorFactory InjectorFactory { get; set; } - /// /// Initializes a new instance of the class. /// @@ -41,10 +41,20 @@ public class PropertyReflectionStrategy : NinjectComponent, IPlanningStrategy /// The injector factory component. public PropertyReflectionStrategy(ISelector selector, IInjectorFactory injectorFactory) { - Selector = selector; - InjectorFactory = injectorFactory; + this.Selector = selector; + this.InjectorFactory = injectorFactory; } + /// + /// Gets the selector component. + /// + public ISelector Selector { get; private set; } + + /// + /// Gets the injector factory component. + /// + public IInjectorFactory InjectorFactory { get; private set; } + /// /// Adds a to the plan for each property /// that should be injected. @@ -52,8 +62,10 @@ public PropertyReflectionStrategy(ISelector selector, IInjectorFactory injectorF /// The plan that is being generated. public void Execute(IPlan plan) { - foreach (PropertyInfo property in Selector.SelectPropertiesForInjection(plan.Type)) - plan.Add(new PropertyInjectionDirective(property, InjectorFactory.Create(property))); + foreach (PropertyInfo property in this.Selector.SelectPropertiesForInjection(plan.Type)) + { + plan.Add(new PropertyInjectionDirective(property, this.InjectorFactory.Create(property))); + } } } } \ No newline at end of file diff --git a/src/Ninject/Planning/Targets/ITarget.cs b/src/Ninject/Planning/Targets/ITarget.cs index 06d0841d..f8925df3 100644 --- a/src/Ninject/Planning/Targets/ITarget.cs +++ b/src/Ninject/Planning/Targets/ITarget.cs @@ -1,25 +1,40 @@ -#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.Activation; -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.Planning.Targets { + using System; + using System.Reflection; + using Ninject.Activation; + using Ninject.Planning.Bindings; + /// /// Represents a site on a type where a value will be injected. /// - public interface ITarget + public interface ITarget +#if !NO_CUSTOM_ATTRIBUTE_PROVIDER + : ICustomAttributeProvider +#endif { /// /// Gets the type of the target. @@ -64,20 +79,15 @@ public interface ITarget /// The resolved value. object ResolveWithin(IContext parent); +#if NO_CUSTOM_ATTRIBUTE_PROVIDER /// - /// Determines if an attribute is defined on the target - /// - /// Type of attribute - /// Check base types - /// - bool IsDefined(Type attributeType, bool inherit); - - /// - /// Determines if an attribute is defined on the target's parent + /// Determines if the target has the specified attribute. /// - /// Type of attribute - /// Parent type to check - /// - bool IsDefinedOnParent(Type attributeType, Type parent); + /// The type of attribute + /// + /// true if the specified member has attribute; otherwise, false. + /// + bool HasAttribute(Type attributeType); +#endif } } \ No newline at end of file diff --git a/src/Ninject/Planning/Targets/ParameterTarget.cs b/src/Ninject/Planning/Targets/ParameterTarget.cs index ad7cb6a9..748f4eb6 100644 --- a/src/Ninject/Planning/Targets/ParameterTarget.cs +++ b/src/Ninject/Planning/Targets/ParameterTarget.cs @@ -1,40 +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.Reflection; -using Ninject.Infrastructure; -#if WINRT -using Ninject.Infrastructure.Language; -using System.Collections.Generic; -#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.Planning.Targets { + using System; + using System.Reflection; + using Ninject.Infrastructure; + /// /// Represents an injection target for a . /// - public class ParameterTarget : - Target - + public class ParameterTarget : Target { - private readonly Future defaultValue; + private readonly Lazy defaultValue; + + /// + /// Initializes a new instance of the class. + /// + /// The method that defines the parameter. + /// The parameter that this target represents. + public ParameterTarget(MethodBase method, ParameterInfo site) + : base(method, site) + { + this.defaultValue = new Lazy(() => site.DefaultValue); + } /// /// Gets the name of the target. /// public override string Name { - get { return Site.Name; } + get { return this.Site.Name; } } /// @@ -42,36 +58,17 @@ public override string Name /// public override Type Type { - get { return Site.ParameterType; } + get { return this.Site.ParameterType; } } -// Windows Phone doesn't support default values and returns null instead of DBNull. -#if !WINDOWS_PHONE /// /// Gets a value indicating whether the target has a default value. /// public override bool HasDefaultValue { - get + get { -#if PCL - throw new NotImplementedException(); -#else -#if NETSTANDARD1_3 - var val = defaultValue.Value; - - if (val != null) - { - var name = val.GetType().FullName; - if (name == "System.DBNull") // WINRT doesn't expose DBNull as a type, but it's still returned as the default - return false; - - } - return true; -#else - return defaultValue.Value != DBNull.Value; -#endif -#endif + return this.defaultValue.Value != DBNull.Value; } } @@ -81,52 +78,7 @@ public override bool HasDefaultValue /// If the item does not have a default value. public override object DefaultValue { - get { return HasDefaultValue ? defaultValue.Value : base.DefaultValue; } - } -#endif - - /// - /// Initializes a new instance of the class. - /// - /// The method that defines the parameter. - /// The parameter that this target represents. - public ParameterTarget(MethodBase method, ParameterInfo site) : base(method -#if !WINRT - , site -#endif - ) - { - defaultValue = new Future(() => site.DefaultValue); - -#if WINRT - Site = site; -#endif - } - -#if WINRT - - public ParameterInfo Site { get; private set; } - - public override IEnumerable GetCustomAttributes(bool inherit) - { - return Site.GetCustomAttributes(inherit); - } - public override IEnumerable GetCustomAttributes(Type attributeType, bool inherit) - { - Ensure.ArgumentNotNull(attributeType, "attributeType"); - return Site.GetCustomAttributes(attributeType, inherit); - } - - public override bool IsDefined(Type attributeType, bool inherit) - { - Ensure.ArgumentNotNull(attributeType, "attributeType"); - return Site.IsDefined(attributeType, inherit); - } - - protected override bool ReadOptionalFromTarget() - { - return Site.HasAttribute(typeof(OptionalAttribute)); + get { return this.HasDefaultValue ? this.defaultValue.Value : base.DefaultValue; } } -#endif } } \ No newline at end of file diff --git a/src/Ninject/Planning/Targets/PropertyTarget.cs b/src/Ninject/Planning/Targets/PropertyTarget.cs index a4769984..b30cff56 100644 --- a/src/Ninject/Planning/Targets/PropertyTarget.cs +++ b/src/Ninject/Planning/Targets/PropertyTarget.cs @@ -1,55 +1,59 @@ -#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; - -#if NETSTANDARD1_3 -using System.Collections.Generic; -using Ninject.Infrastructure; -using Ninject.Infrastructure.Language; -#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.Planning.Targets { + using System; + using System.Reflection; + /// /// Represents an injection target for a . /// public class PropertyTarget : Target - { /// - /// Gets the name of the target. + /// Initializes a new instance of the class. /// - public override string Name + /// The property that this target represents. + public PropertyTarget(PropertyInfo site) + : base(site, site) { - get { return Site.Name; } } /// - /// Gets the type of the target. + /// Gets the name of the target. /// - public override Type Type + public override string Name { - get { return Site.PropertyType; } + get { return this.Site.Name; } } /// - /// Initializes a new instance of the class. + /// Gets the type of the target. /// - /// The property that this target represents. - public PropertyTarget(PropertyInfo site) : base(site, site) + public override Type Type { - + get { return this.Site.PropertyType; } } - } } \ No newline at end of file diff --git a/src/Ninject/Planning/Targets/Target.cs b/src/Ninject/Planning/Targets/Target.cs index 8360bd89..668e6c2d 100644 --- a/src/Ninject/Planning/Targets/Target.cs +++ b/src/Ninject/Planning/Targets/Target.cs @@ -1,39 +1,63 @@ -#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.Activation; -using Ninject.Infrastructure; -using Ninject.Infrastructure.Introspection; -using Ninject.Infrastructure.Language; -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.Planning.Targets { + using System; + using System.Collections.Generic; + using System.Linq; + using System.Reflection; + using Ninject.Activation; + using Ninject.Infrastructure; + using Ninject.Infrastructure.Introspection; + using Ninject.Infrastructure.Language; + using Ninject.Planning.Bindings; + /// /// Represents a site on a type where a value can be injected. /// /// The type of site this represents. - public abstract class Target : ITarget -#if !NETSTANDARD1_3 +#if !NO_CUSTOM_ATTRIBUTE_PROVIDER where T : ICustomAttributeProvider #endif - { - private readonly Future> constraint; - private readonly Future isOptional; + private readonly Lazy> constraint; + private readonly Lazy isOptional; + + /// + /// Initializes a new instance of the class. + /// + /// The member that contains the target. + /// The site represented by the target. + protected Target(MemberInfo member, T site) + { + this.Member = member; + this.Site = site; + + this.constraint = new Lazy>(this.ReadConstraintFromTarget); + this.isOptional = new Lazy(this.ReadOptionalFromTarget); + } /// /// Gets the member that contains the target. @@ -41,7 +65,7 @@ public abstract class Target : ITarget public MemberInfo Member { get; private set; } /// - /// Gets or sets the site (property, parameter, etc.) represented by the target. + /// Gets the site (property, parameter, etc.) represented by the target. /// public T Site { get; private set; } @@ -60,7 +84,7 @@ public abstract class Target : ITarget /// public Func Constraint { - get { return this.constraint; } + get { return this.constraint.Value; } } /// @@ -68,7 +92,7 @@ public abstract class Target : ITarget /// public bool IsOptional { - get { return this.isOptional; } + get { return this.isOptional.Value; } } /// @@ -88,53 +112,28 @@ public virtual object DefaultValue get { throw new InvalidOperationException(ExceptionFormatter.TargetDoesNotHaveADefaultValue(this)); } } - /// - /// Initializes a new instance of the Target<T> class. - /// - /// The member that contains the target. - /// The site represented by the target. - protected Target(MemberInfo member, T site) - { - this.Member = member; - this.Site = site; - - this.constraint = new Future>(ReadConstraintFromTarget); - this.isOptional = new Future(ReadOptionalFromTarget); - } - - - +#if !NO_CUSTOM_ATTRIBUTE_PROVIDER /// /// Returns an array of custom attributes of a specified type defined on the target. /// /// The type of attribute to search for. /// Whether to look up the hierarchy chain for inherited custom attributes. /// An array of custom attributes of the specified type. - public IEnumerable - - GetCustomAttributes(Type attributeType, bool inherit) - + public object[] GetCustomAttributes(Type attributeType, bool inherit) { - - return ExtensionsForICustomAttributeProvider.GetCustomAttributesExtended(Site, attributeType, inherit); - + return this.Site.GetCustomAttributesExtended(attributeType, inherit).ToArray(); } - /// /// Returns an array of custom attributes defined on the target. /// /// Whether to look up the hierarchy chain for inherited custom attributes. /// An array of custom attributes. - public IEnumerable GetCustomAttributes(bool inherit) - + public object[] GetCustomAttributes(bool inherit) { - - return ExtensionsForICustomAttributeProvider.GetCustomAttributes(Site, (inherit)); - + return this.Site.GetCustomAttributes(inherit); } - /// /// Returns a value indicating whether an attribute of the specified type is defined on the target. /// @@ -142,26 +141,22 @@ public IEnumerable GetCustomAttributes(bool inherit) /// Whether to look up the hierarchy chain for inherited custom attributes. /// True if such an attribute is defined; otherwise false. public bool IsDefined(Type attributeType, bool inherit) - { - - return ExtensionsForICustomAttributeProvider.IsDefined(Site, attributeType, inherit); - + return this.Site.IsDefined(attributeType, inherit); } - - +#else /// - /// Determines whether the parent has attribute. + /// Determines if the target has the specified attribute. /// - /// The parent. - /// The type of the attribute. + /// The type of attribute /// - /// true if the specified member has attribute; otherwise, false. + /// true if the specified member has attribute; otherwise, false. /// - public bool IsDefinedOnParent(Type attributeType, Type parent) + public bool HasAttribute(Type attributeType) { - return parent.GetTypeInfo().HasAttribute(attributeType); + return this.Site.HasAttribute(attributeType); } +#endif /// /// Resolves a value for the target within the specified parent context. @@ -170,26 +165,30 @@ public bool IsDefinedOnParent(Type attributeType, Type parent) /// The resolved value. public object ResolveWithin(IContext parent) { - if (Type.IsArray) + if (this.Type.IsArray) { - Type service = Type.GetElementType(); - return GetValues(service, parent).CastSlow(service).ToArraySlow(service); + var service = this.Type.GetElementType(); + return this.GetValues(service, parent).CastSlow(service).ToArraySlow(service); } - if (Type.GetTypeInfo().IsGenericType) + if (this.Type.GetTypeInfo().IsGenericType) { - Type gtd = Type.GetGenericTypeDefinition(); + var gtd = this.Type.GetGenericTypeDefinition(); - Type service = Type.GenericTypeArguments[0]; + var service = this.Type.GenericTypeArguments[0]; if (gtd == typeof(List<>) || gtd == typeof(IList<>) || gtd == typeof(ICollection<>)) - return GetValues(service, parent).CastSlow(service).ToListSlow(service); + { + return this.GetValues(service, parent).CastSlow(service).ToListSlow(service); + } if (gtd == typeof(IEnumerable<>)) - return GetValues(service, parent).CastSlow(service); + { + return this.GetValues(service, parent).CastSlow(service); + } } - return GetValue(Type, parent); + return this.GetValue(this.Type, parent); } /// @@ -223,27 +222,27 @@ protected virtual object GetValue(Type service, IContext parent) /// /// if it is optional; otherwise . protected virtual bool ReadOptionalFromTarget() - { - - return ExtensionsForICustomAttributeProvider.HasAttribute(Site, typeof(OptionalAttribute)); - + return this.Site.HasAttribute(typeof(OptionalAttribute)); } - /// /// Reads the resolution constraint from target. /// /// The resolution constraint. protected virtual Func ReadConstraintFromTarget() { - var attributes = this.GetCustomAttributes(typeof(ConstraintAttribute), true).Cast().ToList(); + var attributes = this.Site.GetCustomAttributesExtended(typeof(ConstraintAttribute), true).Cast().ToList(); if (attributes == null || attributes.Count == 0) + { return null; + } if (attributes.Count == 1) + { return attributes[0].Matches; + } return metadata => attributes.All(attribute => attribute.Matches(metadata)); } diff --git a/src/Ninject/Properties/AssemblyInfo.cs b/src/Ninject/Properties/AssemblyInfo.cs index 9699df7f..c364dcef 100644 --- a/src/Ninject/Properties/AssemblyInfo.cs +++ b/src/Ninject/Properties/AssemblyInfo.cs @@ -1,13 +1,31 @@ -using System.Resources; -using System.Reflection; -using System.Runtime.CompilerServices; -using System.Runtime.InteropServices; -using System.Security; +//------------------------------------------------------------------------------------------------- +// +// 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. +// +//------------------------------------------------------------------------------------------------- -// General Information about an assembly is controlled through the following -// set of attributes. Change these attribute values to modify the information -// associated with an assembly. +using System.Reflection; +[assembly: AssemblyTitle("Ninject Core Library")] -[assembly: AssemblyDescriptionAttribute("IoC container")] -//[assembly: SecurityTransparent] +#if !NO_PARTIAL_TRUST +[assembly: AllowPartiallyTrustedCallers] +#endif +[assembly: AssemblyDescription("IoC container")] \ No newline at end of file diff --git a/src/Ninject/ReadonlyKernel.cs b/src/Ninject/ReadonlyKernel.cs index 817605c4..316a3e7a 100644 --- a/src/Ninject/ReadonlyKernel.cs +++ b/src/Ninject/ReadonlyKernel.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 Ninject.Activation; @@ -20,7 +44,7 @@ /// /// The readonly kernel /// - public class ReadonlyKernel : DisposableObject, IReadOnlyKernel + public class ReadOnlyKernel : DisposableObject, IReadOnlyKernel { private readonly ICache cache; private readonly IPlanner planner; @@ -34,7 +58,7 @@ public class ReadonlyKernel : DisposableObject, IReadOnlyKernel private Dictionary> bindings = new Dictionary>(); /// - /// Initializes a new instance of the class. + /// Initializes a new instance of the class. /// /// The preconfigured bindings /// Dependency injection for @@ -45,11 +69,11 @@ public class ReadonlyKernel : DisposableObject, IReadOnlyKernel /// Dependency injection for all missng binding resolvers /// Dependency injection for for /// Dependency injection for - public ReadonlyKernel( - Multimap bindings, - ICache cache, - IPlanner planner, - IPipeline pipeline, + public ReadOnlyKernel( + Multimap bindings, + ICache cache, + IPlanner planner, + IPipeline pipeline, IBindingPrecedenceComparer bindingPrecedenceComparer, IEnumerable bindingResolvers, IEnumerable missingBindingResolvers, @@ -71,13 +95,16 @@ public class ReadonlyKernel : DisposableObject, IReadOnlyKernel this.InitializeBindings(selector); } + /// + public INinjectSettings Settings { get; private set; } + /// public void Inject(object instance, params IParameter[] parameters) { - Ensure.ArgumentNotNull(instance, "instance"); - Ensure.ArgumentNotNull(parameters, "parameters"); + Contract.Requires(instance != null); + Contract.Requires(parameters != null); - Type service = instance.GetType(); + var service = instance.GetType(); var binding = new Binding(service); var request = this.CreateRequest(service, null, parameters, false, false); @@ -92,14 +119,14 @@ public void Inject(object instance, params IParameter[] parameters) /// public bool CanResolve(IRequest request) { - Ensure.ArgumentNotNull(request, "request"); + Contract.Requires(request != null); return this.GetBindings(request.Service).Any(b => this.SatifiesRequest(request, b)); } /// public bool CanResolve(IRequest request, bool ignoreImplicitBindings) { - Ensure.ArgumentNotNull(request, "request"); + Contract.Requires(request != null); return this.GetBindings(request.Service) .Any(binding => (!ignoreImplicitBindings || !binding.IsImplicit) && this.SatifiesRequest(request, binding)); } @@ -107,82 +134,16 @@ public bool CanResolve(IRequest request, bool ignoreImplicitBindings) /// public IEnumerable Resolve(IRequest request) { - Ensure.ArgumentNotNull(request, "request"); - - return Resolve(request, true); - } - - private IEnumerable Resolve(IRequest request, bool requestMissingBindings) - { - var resolveBindings = this.GetBindings(request.Service).Where(b => this.SatifiesRequest(request, b)); - var resolveBindingsIterator = resolveBindings.GetEnumerator(); - - if (!resolveBindingsIterator.MoveNext()) - { - return this.ResolveWithMissingBindings(request, requestMissingBindings); - } - - if (request.IsUnique) - { - var first = resolveBindingsIterator.Current; - if (resolveBindingsIterator.MoveNext() && - this.bindingPrecedenceComparer.Compare(first, resolveBindingsIterator.Current) == 0) - { - if (request.IsOptional && !request.ForceUnique) - { - return Enumerable.Empty(); - } - - var formattedBindings = - from binding in resolveBindings - let context = this.CreateContext(request, binding) - select binding.Format(context); - throw new ActivationException(ExceptionFormatter.CouldNotUniquelyResolveBinding(request, formattedBindings.ToArray())); - } - - return new object[] { this.CreateContext(request, first).Resolve() }; - } - else - { - return this.ResolveMultiple(request); - } - } - - private IEnumerable ResolveMultiple(IRequest request) - { - var selectedBindings = this.GetBindings(request.Service).Where(b => this.SatifiesRequest(request, b)); - var skipImplicit = false; + Contract.Requires(request != null); - foreach (var binding in selectedBindings.TakeWhile(binding => !binding.IsImplicit || !skipImplicit)) - { - skipImplicit = !binding.IsImplicit; - yield return this.CreateContext(request, binding).Resolve(); - } - } - - private IEnumerable ResolveWithMissingBindings(IRequest request, bool handleMissingBindings) - { - if (handleMissingBindings) - { - if (this.HandleMissingBinding(request)) - { - return this.Resolve(request, false); - } - } - - if (request.IsOptional) - { - return Enumerable.Empty(); - } - - throw new ActivationException(ExceptionFormatter.CouldNotResolveBinding(request)); + return this.Resolve(request, true); } /// public IRequest CreateRequest(Type service, Func constraint, IEnumerable parameters, bool isOptional, bool isUnique) { - Ensure.ArgumentNotNull(service, "service"); - Ensure.ArgumentNotNull(parameters, "parameters"); + Contract.Requires(service != null); + Contract.Requires(parameters != null); return new Request(service, constraint, parameters, null, isOptional, isUnique); } @@ -190,13 +151,10 @@ public IRequest CreateRequest(Type service, Func constra /// public bool Release(object instance) { - Ensure.ArgumentNotNull(instance, "instance"); + Contract.Requires(instance != null); return this.cache.Release(instance); } - /// - public INinjectSettings Settings { get; private set; } - /// public object GetService(Type serviceType) { @@ -206,7 +164,7 @@ public object GetService(Type serviceType) /// public override void Dispose(bool disposing) { - if (disposing && !IsDisposed) + if (disposing && !this.IsDisposed) { this.cache.Clear(); } @@ -217,7 +175,7 @@ public override void Dispose(bool disposing) /// public IEnumerable GetBindings(Type service) { - Ensure.ArgumentNotNull(service, "service"); + Contract.Requires(service != null); List result; if (this.bindingCache.TryGetValue(service, out result)) @@ -231,8 +189,8 @@ public IEnumerable GetBindings(Type service) return result; } - result = bindingResolvers.SelectMany(resolver => resolver.Resolve(this.bindings, service)) - .OrderByDescending(b => b, bindingPrecedenceComparer) + result = this.bindingResolvers.SelectMany(resolver => resolver.Resolve(this.bindings, service)) + .OrderByDescending(b => b, this.bindingPrecedenceComparer) .ToList(); if (result.Count > 0) { @@ -264,7 +222,7 @@ protected virtual bool SatifiesRequest(IRequest request, IBinding binding) /// True if the missing binding can be handled; otherwise false. protected virtual bool HandleMissingBinding(IRequest request) { - Ensure.ArgumentNotNull(request, "request"); + Contract.Requires(request != null); var bindings = this.GetBindingsFromFirstResolverThatReturnsAtLeastOneBinding(request); if (bindings == null) @@ -276,7 +234,10 @@ protected virtual bool HandleMissingBinding(IRequest request) lock (this.missingBindingCacheLock) { - if (CanResolve(request)) return true; + if (this.CanResolve(request)) + { + return true; + } var newBindings = new Dictionary>(this.bindings); bindings.GroupBy(b => b.Service, b => b, (service, b) => new { service, bindings = b }) @@ -311,12 +272,78 @@ protected virtual bool HandleMissingBinding(IRequest request) /// The created context. protected virtual IContext CreateContext(IRequest request, IBinding binding) { - Ensure.ArgumentNotNull(request, "request"); - Ensure.ArgumentNotNull(binding, "binding"); + Contract.Requires(request != null); + Contract.Requires(binding != null); return new Context(this, request, binding, this.cache, this.planner, this.pipeline); } + private IEnumerable ResolveWithMissingBindings(IRequest request, bool handleMissingBindings) + { + if (handleMissingBindings) + { + if (this.HandleMissingBinding(request)) + { + return this.Resolve(request, false); + } + } + + if (request.IsOptional) + { + return Enumerable.Empty(); + } + + throw new ActivationException(ExceptionFormatter.CouldNotResolveBinding(request)); + } + + private IEnumerable ResolveMultiple(IRequest request) + { + var selectedBindings = this.GetBindings(request.Service).Where(b => this.SatifiesRequest(request, b)); + var skipImplicit = false; + + foreach (var binding in selectedBindings.TakeWhile(binding => !binding.IsImplicit || !skipImplicit)) + { + skipImplicit = !binding.IsImplicit; + yield return this.CreateContext(request, binding).Resolve(); + } + } + + private IEnumerable Resolve(IRequest request, bool requestMissingBindings) + { + var resolveBindings = this.GetBindings(request.Service).Where(b => this.SatifiesRequest(request, b)); + var resolveBindingsIterator = resolveBindings.GetEnumerator(); + + if (!resolveBindingsIterator.MoveNext()) + { + return this.ResolveWithMissingBindings(request, requestMissingBindings); + } + + if (request.IsUnique) + { + var first = resolveBindingsIterator.Current; + if (resolveBindingsIterator.MoveNext() && + this.bindingPrecedenceComparer.Compare(first, resolveBindingsIterator.Current) == 0) + { + if (request.IsOptional && !request.ForceUnique) + { + return Enumerable.Empty(); + } + + var formattedBindings = + from binding in resolveBindings + let context = this.CreateContext(request, binding) + select binding.Format(context); + throw new ActivationException(ExceptionFormatter.CouldNotUniquelyResolveBinding(request, formattedBindings.ToArray())); + } + + return new object[] { this.CreateContext(request, first).Resolve() }; + } + else + { + return this.ResolveMultiple(request); + } + } + private List GetBindingsFromFirstResolverThatReturnsAtLeastOneBinding(IRequest request) { return this.missingBindingResolvers @@ -333,7 +360,7 @@ private void AddReadonlyKernelBinding(T readonlyKernel, Multimap b)) + foreach (var binding in this.bindings.Values.SelectMany(b => b)) { binding.InitializeProviderCallback(selector); this.GetBindings(binding.Service); diff --git a/src/Ninject/Selection/Heuristics/IConstructorScorer.cs b/src/Ninject/Selection/Heuristics/IConstructorScorer.cs index a262cb96..b69488f1 100644 --- a/src/Ninject/Selection/Heuristics/IConstructorScorer.cs +++ b/src/Ninject/Selection/Heuristics/IConstructorScorer.cs @@ -1,23 +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.Reflection; -using Ninject.Activation; -using Ninject.Components; -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.Selection.Heuristics { + using Ninject.Activation; + using Ninject.Components; + using Ninject.Planning.Directives; + /// /// Generates scores for constructors, to determine which is the best one to call during activation. /// diff --git a/src/Ninject/Selection/Heuristics/IInjectionHeuristic.cs b/src/Ninject/Selection/Heuristics/IInjectionHeuristic.cs index 51b93c72..536ea985 100644 --- a/src/Ninject/Selection/Heuristics/IInjectionHeuristic.cs +++ b/src/Ninject/Selection/Heuristics/IInjectionHeuristic.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.Selection.Heuristics { + using System.Reflection; + using Ninject.Components; + /// /// Determines whether members should be injected during activation. /// diff --git a/src/Ninject/Selection/Heuristics/SpecificConstructorSelector.cs b/src/Ninject/Selection/Heuristics/SpecificConstructorSelector.cs index 1ea36870..7a9a9dcf 100644 --- a/src/Ninject/Selection/Heuristics/SpecificConstructorSelector.cs +++ b/src/Ninject/Selection/Heuristics/SpecificConstructorSelector.cs @@ -1,13 +1,17 @@ -//------------------------------------------------------------------------------- -// -// Copyright (c) 2011 Ninject Project Contributors -// Author: 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) // -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. +// 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, @@ -15,7 +19,7 @@ // See the License for the specific language governing permissions and // limitations under the License. // -//------------------------------------------------------------------------------- +//------------------------------------------------------------------------------------------------- namespace Ninject.Selection.Heuristics { @@ -48,7 +52,7 @@ public SpecificConstructorSelector(ConstructorInfo constructorInfo) /// The constructor's score. public virtual int Score(IContext context, ConstructorInjectionDirective directive) { - return directive.Constructor.Equals(constructorInfo) ? 1 : 0; + return directive.Constructor.Equals(this.constructorInfo) ? 1 : 0; } } } \ No newline at end of file diff --git a/src/Ninject/Selection/Heuristics/StandardConstructorScorer.cs b/src/Ninject/Selection/Heuristics/StandardConstructorScorer.cs index f82ec74f..17849745 100644 --- a/src/Ninject/Selection/Heuristics/StandardConstructorScorer.cs +++ b/src/Ninject/Selection/Heuristics/StandardConstructorScorer.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,18 +19,18 @@ // See the License for the specific language governing permissions and // limitations under the License. // -//------------------------------------------------------------------------------- +//------------------------------------------------------------------------------------------------- namespace Ninject.Selection.Heuristics { using System; using System.Collections; + using System.Diagnostics.Contracts; using System.Linq; using System.Reflection; using Ninject.Activation; using Ninject.Components; using Ninject.Infrastructure; - using Ninject.Infrastructure.Language; using Ninject.Parameters; using Ninject.Planning.Directives; using Ninject.Planning.Targets; @@ -49,8 +49,8 @@ public class StandardConstructorScorer : NinjectComponent, IConstructorScorer /// The constructor's score. public virtual int Score(IContext context, ConstructorInjectionDirective directive) { - Ensure.ArgumentNotNull(context, "context"); - Ensure.ArgumentNotNull(directive, "constructor"); + Contract.Requires(context != null); + Contract.Requires(directive != null); if (directive.HasInjectAttribute) { @@ -60,13 +60,13 @@ public virtual int Score(IContext context, ConstructorInjectionDirective directi var score = 1; foreach (ITarget target in directive.Targets) { - if (ParameterExists(context, target)) + if (this.ParameterExists(context, target)) { score++; continue; } - - if (BindingExists(context, target)) + + if (this.BindingExists(context, target)) { score++; continue; @@ -78,7 +78,7 @@ public virtual int Score(IContext context, ConstructorInjectionDirective directi score += int.MinValue; } } - + return score; } @@ -90,8 +90,8 @@ public virtual int Score(IContext context, ConstructorInjectionDirective directi /// Whether a binding exists for the target in the given context. protected virtual bool BindingExists(IContext context, ITarget target) { - return this.BindingExists(context.Kernel, context, target); - } + return this.BindingExists(context.Kernel, context, target); + } /// /// Checkes whether a binding exists for a given target on the specified kernel. @@ -102,15 +102,28 @@ protected virtual bool BindingExists(IContext context, ITarget target) /// Whether a binding exists for the target in the given context. protected virtual bool BindingExists(IReadOnlyKernel kernel, IContext context, ITarget target) { - var targetType = GetTargetType(target); + var targetType = this.GetTargetType(target); return kernel.GetBindings(targetType).Any(b => !b.IsImplicit) || target.HasDefaultValue; } + /// + /// Checks whether any parameters exist for the given target.. + /// + /// The context. + /// The target. + /// Whether a parameter exists for the target in the given context. + protected virtual bool ParameterExists(IContext context, ITarget target) + { + return context + .Parameters.OfType() + .Any(parameter => parameter.AppliesToTarget(context, target)); + } + private Type GetTargetType(ITarget target) { var targetType = target.Type; - + if (targetType.IsArray) { targetType = targetType.GetElementType(); @@ -119,7 +132,7 @@ private Type GetTargetType(ITarget target) var typeInfo = targetType.GetTypeInfo(); if (typeInfo.IsGenericType) { - if(typeInfo.ImplementedInterfaces.Any(type => type == typeof(IEnumerable))) + if (typeInfo.ImplementedInterfaces.Any(type => type == typeof(IEnumerable))) { targetType = typeInfo.GenericTypeArguments[0]; } @@ -127,18 +140,5 @@ private Type GetTargetType(ITarget target) return targetType; } - - /// - /// Checks whether any parameters exist for the given target.. - /// - /// The context. - /// The target. - /// Whether a parameter exists for the target in the given context. - protected virtual bool ParameterExists(IContext context, ITarget target) - { - return context - .Parameters.OfType() - .Any(parameter => parameter.AppliesToTarget(context, target)); - } } -} +} \ No newline at end of file diff --git a/src/Ninject/Selection/Heuristics/StandardInjectionHeuristic.cs b/src/Ninject/Selection/Heuristics/StandardInjectionHeuristic.cs index 51c83a10..89591136 100644 --- a/src/Ninject/Selection/Heuristics/StandardInjectionHeuristic.cs +++ b/src/Ninject/Selection/Heuristics/StandardInjectionHeuristic.cs @@ -1,22 +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.Reflection; -using Ninject.Components; -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.Selection.Heuristics { + using System.Reflection; + using Ninject.Components; + using Ninject.Infrastructure.Language; + /// /// Determines whether members should be injected during activation by checking /// if they are decorated with an injection marker attribute. @@ -34,19 +44,21 @@ public virtual bool ShouldInject(MemberInfo member) if (propertyInfo != null) { - bool injectNonPublic = Settings.InjectNonPublic; + var injectNonPublic = this.Settings.InjectNonPublic; var setMethod = propertyInfo.SetMethod; if (setMethod != null && !injectNonPublic) { if (!setMethod.IsPublic) + { setMethod = null; + } } - return member.HasAttribute(Settings.InjectAttribute) && setMethod != null; + return member.HasAttribute(this.Settings.InjectAttribute) && setMethod != null; } - return member.HasAttribute(Settings.InjectAttribute); + return member.HasAttribute(this.Settings.InjectAttribute); } } } \ No newline at end of file diff --git a/src/Ninject/Selection/ISelector.cs b/src/Ninject/Selection/ISelector.cs index dd6b8ccc..3e27799a 100644 --- a/src/Ninject/Selection/ISelector.cs +++ b/src/Ninject/Selection/ISelector.cs @@ -1,22 +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 System.Reflection; -using Ninject.Components; -using Ninject.Selection.Heuristics; -#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.Selection { + using System; + using System.Collections.Generic; + using System.Reflection; + using Ninject.Components; + using Ninject.Selection.Heuristics; + /// /// Selects members for injection. /// diff --git a/src/Ninject/Selection/Selector.cs b/src/Ninject/Selection/Selector.cs index f3551bfd..ea3e516b 100644 --- a/src/Ninject/Selection/Selector.cs +++ b/src/Ninject/Selection/Selector.cs @@ -1,31 +1,54 @@ -#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.Components; -using Ninject.Infrastructure; -using Ninject.Selection.Heuristics; -#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.Selection { + using System; + using System.Collections.Generic; + using System.Linq; + using System.Reflection; + using Ninject.Components; using Ninject.Infrastructure.Language; + using Ninject.Selection.Heuristics; /// /// Selects members for injection. /// public class Selector : NinjectComponent, ISelector { + private const BindingFlags DefaultFlags = BindingFlags.Public | BindingFlags.Instance; + + /// + /// Initializes a new instance of the class. + /// + /// The constructor scorer. + /// The injection heuristics. + public Selector(IConstructorScorer constructorScorer, IEnumerable injectionHeuristics) + { + this.ConstructorScorer = constructorScorer; + this.InjectionHeuristics = injectionHeuristics.ToList(); + } + /// /// Gets or sets the constructor scorer. /// @@ -37,14 +60,18 @@ public class Selector : NinjectComponent, ISelector public ICollection InjectionHeuristics { get; private set; } /// - /// Initializes a new instance of the class. + /// Gets the default binding flags. /// - /// The constructor scorer. - /// The injection heuristics. - public Selector(IConstructorScorer constructorScorer, IEnumerable injectionHeuristics) + protected virtual BindingFlags Flags { - ConstructorScorer = constructorScorer; - InjectionHeuristics = injectionHeuristics.ToList(); + get + { +#if !NO_LCG + return this.Settings.InjectNonPublic ? (DefaultFlags | BindingFlags.NonPublic) : DefaultFlags; +#else + return DefaultFlags; +#endif + } } /// @@ -52,13 +79,15 @@ public Selector(IConstructorScorer constructorScorer, IEnumerable /// The type. /// The selected constructor, or if none were available. - public virtual IEnumerable SelectConstructorsForInjection(Type type) + public virtual IEnumerable SelectConstructorsForInjection(Type type) { if (type.GetTypeInfo().IsSubclassOf(typeof(MulticastDelegate))) + { return null; - var tInfo = type.GetTypeInfo(); - var constructors = tInfo.DeclaredConstructors.FilterPublic(Settings.InjectNonPublic); - return constructors.Any() ? constructors : null; + } + + var constructors = type.GetConstructors(this.Flags); + return constructors.Length == 0 ? null : constructors; } /// @@ -68,14 +97,13 @@ public virtual IEnumerable SelectConstructorsForInjection(Type /// A series of the selected properties. public virtual IEnumerable SelectPropertiesForInjection(Type type) { - List properties = new List(); - + var properties = new List(); + properties.AddRange( - type.GetRuntimeProperties().FilterPublic(Settings.InjectNonPublic) + type.GetProperties(this.Flags) .Select(p => p.GetPropertyFromDeclaredType(p)) .Where(p => this.InjectionHeuristics.Any(h => p != null && h.ShouldInject(p)))); - if (this.Settings.InjectParentPrivateProperties) { for (Type parentType = type.GetTypeInfo().BaseType; parentType != null; parentType = parentType.GetTypeInfo().BaseType) @@ -83,15 +111,9 @@ public virtual IEnumerable SelectPropertiesForInjection(Type type) properties.AddRange(this.GetPrivateProperties(type.GetTypeInfo().BaseType)); } } - + return properties; } - - private IEnumerable GetPrivateProperties(Type type) - { - return type.GetRuntimeProperties().FilterPublic(Settings.InjectNonPublic).Where(p => p.DeclaringType == type && p.IsPrivate()) - .Where(p => this.InjectionHeuristics.Any(h => h.ShouldInject(p))); - } /// /// Selects methods that should be injected. @@ -100,31 +122,13 @@ private IEnumerable GetPrivateProperties(Type type) /// A series of the selected methods. public virtual IEnumerable SelectMethodsForInjection(Type type) { - return type.GetRuntimeMethods().FilterPublic(Settings.InjectNonPublic).Where(m => InjectionHeuristics.Any(h => h.ShouldInject(m))); + return type.GetMethods(this.Flags).Where(m => this.InjectionHeuristics.Any(h => h.ShouldInject(m))); } - } -} -namespace Ninject -{ - - internal static class WinRTFilters - { - public static IEnumerable FilterPublic(this IEnumerable input, bool nonPublic) - where T : MethodBase + private IEnumerable GetPrivateProperties(Type type) { - return input.Where(m => !m.IsStatic && (nonPublic || m.IsPublic)); - } - - public static IEnumerable FilterPublic(this IEnumerable input, bool nonPublic) - { - var toReturn = from pi in input - let method = pi.SetMethod ?? pi.GetMethod - where !method.IsStatic && (nonPublic || method.IsPublic) - select pi; - - return toReturn; + return type.GetProperties(this.Flags).Where(p => p.DeclaringType == type && p.IsPrivate()) + .Where(p => this.InjectionHeuristics.Any(h => h.ShouldInject(p))); } } - -} +} \ No newline at end of file diff --git a/src/Ninject/Settings.StyleCop b/src/Ninject/Settings.StyleCop deleted file mode 100644 index e5888388..00000000 --- a/src/Ninject/Settings.StyleCop +++ /dev/null @@ -1,101 +0,0 @@ - - - - castable - - - - - - - - True - - - - - True - - - - - True - - - - - True - - - - - True - - - - - True - - - - - True - - - - - True - - - - - True - - - - - True - - - - - True - - - - - True - - - - - True - - - - - True - - - - - Ninject Project Contributors - Copyright (c) 2009-2014 Ninject Project Contributors - -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. - - - - \ No newline at end of file diff --git a/src/Ninject/StandardKernel.cs b/src/Ninject/StandardKernel.cs index d08bb1f5..5129445d 100644 --- a/src/Ninject/StandardKernel.cs +++ b/src/Ninject/StandardKernel.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,22 +19,12 @@ // See the License for the specific language governing permissions and // limitations under the License. // -//------------------------------------------------------------------------------- - -using System; +//------------------------------------------------------------------------------------------------- namespace Ninject { - using Ninject.Activation; - using Ninject.Activation.Caching; - using Ninject.Activation.Strategies; - using Ninject.Injection; + using System; using Ninject.Modules; - using Ninject.Planning; - using Ninject.Planning.Bindings.Resolvers; - using Ninject.Planning.Strategies; - using Ninject.Selection; - using Ninject.Selection.Heuristics; /// /// The standard implementation of a kernel. @@ -46,7 +36,8 @@ public class StandardKernel : KernelBase /// Initializes a new instance of the class. /// /// The modules to load into the kernel. - public StandardKernel(params INinjectModule[] modules) : base(modules) + public StandardKernel(params INinjectModule[] modules) + : base(modules) { } @@ -55,8 +46,9 @@ public StandardKernel(params INinjectModule[] modules) : base(modules) /// /// The configuration to use. /// The modules to load into the kernel. - public StandardKernel(INinjectSettings settings, params INinjectModule[] modules) : base(settings, modules) + public StandardKernel(INinjectSettings settings, params INinjectModule[] modules) + : base(settings, modules) { } } -} +} \ No newline at end of file diff --git a/src/Ninject/Syntax/BindingRoot.cs b/src/Ninject/Syntax/BindingRoot.cs index b8cffb2c..8665cd62 100644 --- a/src/Ninject/Syntax/BindingRoot.cs +++ b/src/Ninject/Syntax/BindingRoot.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,11 +19,12 @@ // See the License for the specific language governing permissions and // limitations under the License. // -//------------------------------------------------------------------------------- +//------------------------------------------------------------------------------------------------- namespace Ninject.Syntax { using System; + using System.Diagnostics.Contracts; using System.Linq; using Ninject.Infrastructure; @@ -49,16 +50,12 @@ public abstract class BindingRoot : DisposableObject, IBindingRoot /// The fluent syntax public IBindingToSyntax Bind() { -#if PCL - throw new NotImplementedException(); -#else - Type service = typeof(T); + var service = typeof(T); var binding = new Binding(service); this.AddBinding(binding); return new BindingBuilder(binding, this.Settings, service.Format()); -#endif } /// @@ -69,16 +66,12 @@ public IBindingToSyntax Bind() /// The fluent syntax public IBindingToSyntax Bind() { -#if PCL - throw new NotImplementedException(); -#else var firstBinding = new Binding(typeof(T1)); this.AddBinding(firstBinding); this.AddBinding(new Binding(typeof(T2), firstBinding.BindingConfiguration)); var serviceNames = new[] { typeof(T1).Format(), typeof(T2).Format() }; return new BindingBuilder(firstBinding.BindingConfiguration, this.Settings, string.Join(", ", serviceNames)); -#endif } /// @@ -90,9 +83,6 @@ public IBindingToSyntax Bind() /// The fluent syntax public IBindingToSyntax Bind() { -#if PCL - throw new NotImplementedException(); -#else var firstBinding = new Binding(typeof(T1)); this.AddBinding(firstBinding); this.AddBinding(new Binding(typeof(T2), firstBinding.BindingConfiguration)); @@ -100,7 +90,6 @@ public IBindingToSyntax Bind() var serviceNames = new[] { typeof(T1).Format(), typeof(T2).Format(), typeof(T3).Format() }; return new BindingBuilder(firstBinding.BindingConfiguration, this.Settings, string.Join(", ", serviceNames)); -#endif } /// @@ -113,9 +102,6 @@ public IBindingToSyntax Bind() /// The fluent syntax public IBindingToSyntax Bind() { -#if PCL - throw new NotImplementedException(); -#else var firstBinding = new Binding(typeof(T1)); this.AddBinding(firstBinding); this.AddBinding(new Binding(typeof(T2), firstBinding.BindingConfiguration)); @@ -124,7 +110,6 @@ public IBindingToSyntax Bind() var serviceNames = new[] { typeof(T1).Format(), typeof(T2).Format(), typeof(T3).Format(), typeof(T4).Format() }; return new BindingBuilder(firstBinding.BindingConfiguration, this.Settings, string.Join(", ", serviceNames)); -#endif } /// @@ -134,13 +119,11 @@ public IBindingToSyntax Bind() /// The fluent syntax public IBindingToSyntax Bind(params Type[] services) { -#if PCL - throw new NotImplementedException(); -#else - Ensure.ArgumentNotNull(services, "service"); + Contract.Requires(services != null); + if (services.Length == 0) { - throw new ArgumentException("The services must contain at least one type", "services"); + throw new ArgumentException("The services must contain at least one type", "services"); } var firstBinding = new Binding(services[0]); @@ -148,11 +131,10 @@ public IBindingToSyntax Bind(params Type[] services) foreach (var service in services.Skip(1)) { - this.AddBinding(new Binding(service, firstBinding.BindingConfiguration)); + this.AddBinding(new Binding(service, firstBinding.BindingConfiguration)); } return new BindingBuilder(firstBinding, this.Settings, string.Join(", ", services.Select(service => service.Format()).ToArray())); -#endif } /// @@ -161,7 +143,7 @@ public IBindingToSyntax Bind(params Type[] services) /// The service to unbind. public void Unbind() { - Unbind(typeof(T)); + this.Unbind(typeof(T)); } /// @@ -177,8 +159,8 @@ public void Unbind() /// The fluent syntax public IBindingToSyntax Rebind() { - Unbind(); - return Bind(); + this.Unbind(); + return this.Bind(); } /// @@ -189,9 +171,9 @@ public IBindingToSyntax Rebind() /// The fluent syntax. public IBindingToSyntax Rebind() { - Unbind(); - Unbind(); - return Bind(); + this.Unbind(); + this.Unbind(); + return this.Bind(); } /// @@ -203,10 +185,10 @@ public IBindingToSyntax Rebind() /// The fluent syntax. public IBindingToSyntax Rebind() { - Unbind(); - Unbind(); - Unbind(); - return Bind(); + this.Unbind(); + this.Unbind(); + this.Unbind(); + return this.Bind(); } /// @@ -219,11 +201,11 @@ public IBindingToSyntax Rebind() /// The fluent syntax. public IBindingToSyntax Rebind() { - Unbind(); - Unbind(); - Unbind(); - Unbind(); - return Bind(); + this.Unbind(); + this.Unbind(); + this.Unbind(); + this.Unbind(); + return this.Bind(); } /// @@ -235,10 +217,10 @@ public IBindingToSyntax Rebind(params Type[] services) { foreach (var service in services) { - Unbind(service); + this.Unbind(service); } - return Bind(services); + return this.Bind(services); } /// diff --git a/src/Ninject/Syntax/IBindingInNamedWithOrOnSyntax.cs b/src/Ninject/Syntax/IBindingInNamedWithOrOnSyntax.cs index 4849bf9b..bacc6b42 100644 --- a/src/Ninject/Syntax/IBindingInNamedWithOrOnSyntax.cs +++ b/src/Ninject/Syntax/IBindingInNamedWithOrOnSyntax.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.Syntax { @@ -27,10 +27,10 @@ namespace Ninject.Syntax /// Used to set the scope, name, or add additional information or actions to a binding. /// /// The service being bound. - public interface IBindingInNamedWithOrOnSyntax : - IBindingInSyntax, - IBindingNamedSyntax, - IBindingWithSyntax, + public interface IBindingInNamedWithOrOnSyntax : + IBindingInSyntax, + IBindingNamedSyntax, + IBindingWithSyntax, IBindingOnSyntax { } diff --git a/src/Ninject/Syntax/IBindingInSyntax.cs b/src/Ninject/Syntax/IBindingInSyntax.cs index a469f8ff..ba8e533c 100644 --- a/src/Ninject/Syntax/IBindingInSyntax.cs +++ b/src/Ninject/Syntax/IBindingInSyntax.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.Syntax { @@ -47,7 +47,7 @@ public interface IBindingInSyntax : IBindingSyntax /// The fluent syntax. IBindingNamedWithOrOnSyntax InTransientScope(); -#if !NETSTANDARD1_3 && !PCL +#if !CORE /// /// Indicates that instances activated via the binding should be re-used within the same thread. /// diff --git a/src/Ninject/Syntax/IBindingNamedSyntax.cs b/src/Ninject/Syntax/IBindingNamedSyntax.cs index 559512aa..ba2107d9 100644 --- a/src/Ninject/Syntax/IBindingNamedSyntax.cs +++ b/src/Ninject/Syntax/IBindingNamedSyntax.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.Syntax { diff --git a/src/Ninject/Syntax/IBindingNamedWithOrOnSyntax.cs b/src/Ninject/Syntax/IBindingNamedWithOrOnSyntax.cs index cb210271..a3ebb5c1 100644 --- a/src/Ninject/Syntax/IBindingNamedWithOrOnSyntax.cs +++ b/src/Ninject/Syntax/IBindingNamedWithOrOnSyntax.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.Syntax { diff --git a/src/Ninject/Syntax/IBindingOnSyntax.cs b/src/Ninject/Syntax/IBindingOnSyntax.cs index da540864..a692a3bf 100644 --- a/src/Ninject/Syntax/IBindingOnSyntax.cs +++ b/src/Ninject/Syntax/IBindingOnSyntax.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.Syntax { diff --git a/src/Ninject/Syntax/IBindingRoot.cs b/src/Ninject/Syntax/IBindingRoot.cs index 81981967..b474ee1f 100644 --- a/src/Ninject/Syntax/IBindingRoot.cs +++ b/src/Ninject/Syntax/IBindingRoot.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.Syntax { diff --git a/src/Ninject/Syntax/IBindingSyntax.cs b/src/Ninject/Syntax/IBindingSyntax.cs index b24b4a64..8e5b0ff1 100644 --- a/src/Ninject/Syntax/IBindingSyntax.cs +++ b/src/Ninject/Syntax/IBindingSyntax.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.Syntax { diff --git a/src/Ninject/Syntax/IBindingToSyntax{T1,T2,T3,T4}.cs b/src/Ninject/Syntax/IBindingToSyntax{T1,T2,T3,T4}.cs index 91c258f3..412c0391 100644 --- a/src/Ninject/Syntax/IBindingToSyntax{T1,T2,T3,T4}.cs +++ b/src/Ninject/Syntax/IBindingToSyntax{T1,T2,T3,T4}.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.Syntax { @@ -41,7 +41,7 @@ public interface IBindingToSyntax : IBindingSyntax /// /// The implementation type. /// The fluent syntax. - IBindingWhenInNamedWithOrOnSyntax To() + IBindingWhenInNamedWithOrOnSyntax To() where TImplementation : T1, T2, T3, T4; /// @@ -57,7 +57,8 @@ IBindingWhenInNamedWithOrOnSyntax To() /// /// The type of provider to activate. /// The fluent syntax. - IBindingWhenInNamedWithOrOnSyntax ToProvider() where TProvider : IProvider; + IBindingWhenInNamedWithOrOnSyntax ToProvider() + where TProvider : IProvider; /// /// Indicates that the service should be bound to an instance of the specified provider type. @@ -66,7 +67,7 @@ IBindingWhenInNamedWithOrOnSyntax To() /// The type of provider to activate. /// The type of the implementation. /// The fluent syntax. - IBindingWhenInNamedWithOrOnSyntax ToProvider() + IBindingWhenInNamedWithOrOnSyntax ToProvider() where TProvider : IProvider where TImplementation : T1, T2, T3, T4; diff --git a/src/Ninject/Syntax/IBindingToSyntax{T1,T2,T3}.cs b/src/Ninject/Syntax/IBindingToSyntax{T1,T2,T3}.cs index eec74102..ce7e94de 100644 --- a/src/Ninject/Syntax/IBindingToSyntax{T1,T2,T3}.cs +++ b/src/Ninject/Syntax/IBindingToSyntax{T1,T2,T3}.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.Syntax { @@ -40,7 +40,7 @@ public interface IBindingToSyntax : IBindingSyntax /// /// The implementation type. /// The fluent syntax. - IBindingWhenInNamedWithOrOnSyntax To() + IBindingWhenInNamedWithOrOnSyntax To() where TImplementation : T1, T2, T3; /// @@ -56,7 +56,8 @@ IBindingWhenInNamedWithOrOnSyntax To() /// /// The type of provider to activate. /// The fluent syntax. - IBindingWhenInNamedWithOrOnSyntax ToProvider() where TProvider : IProvider; + IBindingWhenInNamedWithOrOnSyntax ToProvider() + where TProvider : IProvider; /// /// Indicates that the service should be bound to an instance of the specified provider type. @@ -65,7 +66,7 @@ IBindingWhenInNamedWithOrOnSyntax To() /// The type of provider to activate. /// The type of the implementation. /// The fluent syntax. - IBindingWhenInNamedWithOrOnSyntax ToProvider() + IBindingWhenInNamedWithOrOnSyntax ToProvider() where TProvider : IProvider where TImplementation : T1, T2, T3; diff --git a/src/Ninject/Syntax/IBindingToSyntax{T1,T2}.cs b/src/Ninject/Syntax/IBindingToSyntax{T1,T2}.cs index 0ea391a1..3ebe0c8c 100644 --- a/src/Ninject/Syntax/IBindingToSyntax{T1,T2}.cs +++ b/src/Ninject/Syntax/IBindingToSyntax{T1,T2}.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.Syntax { @@ -39,7 +39,7 @@ public interface IBindingToSyntax : IBindingSyntax /// /// The implementation type. /// The fluent syntax. - IBindingWhenInNamedWithOrOnSyntax To() + IBindingWhenInNamedWithOrOnSyntax To() where TImplementation : T1, T2; /// @@ -55,7 +55,8 @@ IBindingWhenInNamedWithOrOnSyntax To() /// /// The type of provider to activate. /// The fluent syntax. - IBindingWhenInNamedWithOrOnSyntax ToProvider() where TProvider : IProvider; + IBindingWhenInNamedWithOrOnSyntax ToProvider() + where TProvider : IProvider; /// /// Indicates that the service should be bound to an instance of the specified provider type. @@ -64,7 +65,7 @@ IBindingWhenInNamedWithOrOnSyntax To() /// The type of provider to activate. /// The type of the implementation. /// The fluent syntax. - IBindingWhenInNamedWithOrOnSyntax ToProvider() + IBindingWhenInNamedWithOrOnSyntax ToProvider() where TProvider : IProvider where TImplementation : T1, T2; diff --git a/src/Ninject/Syntax/IBindingToSyntax{T1}.cs b/src/Ninject/Syntax/IBindingToSyntax{T1}.cs index 2f154e1a..c561990b 100644 --- a/src/Ninject/Syntax/IBindingToSyntax{T1}.cs +++ b/src/Ninject/Syntax/IBindingToSyntax{T1}.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.Syntax { @@ -44,7 +44,7 @@ public interface IBindingToSyntax : IBindingSyntax /// /// The implementation type. /// The fluent syntax. - IBindingWhenInNamedWithOrOnSyntax To() + IBindingWhenInNamedWithOrOnSyntax To() where TImplementation : T1; /// @@ -60,7 +60,7 @@ IBindingWhenInNamedWithOrOnSyntax To() /// /// The type of provider to activate. /// The fluent syntax. - IBindingWhenInNamedWithOrOnSyntax ToProvider() + IBindingWhenInNamedWithOrOnSyntax ToProvider() where TProvider : IProvider; /// @@ -116,4 +116,4 @@ IBindingWhenInNamedWithOrOnSyntax ToConstant(T Expression> newExpression) where TImplementation : T1; } -} +} \ No newline at end of file diff --git a/src/Ninject/Syntax/IBindingWhenInNamedWithOrOnSyntax.cs b/src/Ninject/Syntax/IBindingWhenInNamedWithOrOnSyntax.cs index 580532d9..cd1433e0 100644 --- a/src/Ninject/Syntax/IBindingWhenInNamedWithOrOnSyntax.cs +++ b/src/Ninject/Syntax/IBindingWhenInNamedWithOrOnSyntax.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.Syntax { diff --git a/src/Ninject/Syntax/IBindingWhenSyntax.cs b/src/Ninject/Syntax/IBindingWhenSyntax.cs index e40e36b4..49da3626 100644 --- a/src/Ninject/Syntax/IBindingWhenSyntax.cs +++ b/src/Ninject/Syntax/IBindingWhenSyntax.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.Syntax { @@ -68,7 +68,7 @@ public interface IBindingWhenSyntax : IBindingSyntax /// /// Indicates that the binding should be used only for injections on the specified type. /// The type must match exactly the specified type. Types that derive from the specified type - /// will not be considered as valid target. + /// will not be considered as valid target. /// /// The type. /// The fluent syntax. @@ -77,7 +77,7 @@ public interface IBindingWhenSyntax : IBindingSyntax /// /// Indicates that the binding should be used only for injections on the specified type. /// The type must match exactly the specified type. Types that derive from the specified type - /// will not be considered as valid target. + /// will not be considered as valid target. /// /// The type. /// The fluent syntax. @@ -86,7 +86,7 @@ public interface IBindingWhenSyntax : IBindingSyntax /// /// Indicates that the binding should be used only for injections on the specified type. /// The type must match one of the specified types exactly. Types that derive from one of the specified types - /// will not be considered as valid target. + /// will not be considered as valid target. /// Should match at least one of the specified targets /// /// The types. @@ -99,7 +99,8 @@ public interface IBindingWhenSyntax : IBindingSyntax /// /// The type of attribute. /// The fluent syntax. - IBindingInNamedWithOrOnSyntax WhenClassHas() where TAttribute : Attribute; + IBindingInNamedWithOrOnSyntax WhenClassHas() + where TAttribute : Attribute; /// /// Indicates that the binding should be used only when the member being injected has @@ -107,7 +108,8 @@ public interface IBindingWhenSyntax : IBindingSyntax /// /// The type of attribute. /// The fluent syntax. - IBindingInNamedWithOrOnSyntax WhenMemberHas() where TAttribute : Attribute; + IBindingInNamedWithOrOnSyntax WhenMemberHas() + where TAttribute : Attribute; /// /// Indicates that the binding should be used only when the target being injected has @@ -115,7 +117,8 @@ public interface IBindingWhenSyntax : IBindingSyntax /// /// The type of attribute. /// The fluent syntax. - IBindingInNamedWithOrOnSyntax WhenTargetHas() where TAttribute : Attribute; + IBindingInNamedWithOrOnSyntax WhenTargetHas() + where TAttribute : Attribute; /// /// Indicates that the binding should be used only when the class being injected has @@ -170,7 +173,7 @@ public interface IBindingWhenSyntax : IBindingSyntax /// The name to expect. /// The fluent syntax. IBindingInNamedWithOrOnSyntax WhenNoAncestorNamed(string name); - + /// /// Indicates that the binding should be used only when any ancestor matches the specified predicate. /// diff --git a/src/Ninject/Syntax/IBindingWithOrOnSyntax.cs b/src/Ninject/Syntax/IBindingWithOrOnSyntax.cs index 76c2b903..30da20ed 100644 --- a/src/Ninject/Syntax/IBindingWithOrOnSyntax.cs +++ b/src/Ninject/Syntax/IBindingWithOrOnSyntax.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.Syntax { diff --git a/src/Ninject/Syntax/IBindingWithSyntax.cs b/src/Ninject/Syntax/IBindingWithSyntax.cs index b5adc3bf..0acaae79 100644 --- a/src/Ninject/Syntax/IBindingWithSyntax.cs +++ b/src/Ninject/Syntax/IBindingWithSyntax.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.Syntax { @@ -95,7 +95,7 @@ public interface IBindingWithSyntax : IBindingSyntax /// Indicates that the specified constructor argument should be overridden with the specified value. /// /// The type of the argument to override. - /// The callback to invoke to get the value for the argument. + /// The callback to invoke to get the value for the argument. /// The fluent syntax. IBindingWithOrOnSyntax WithConstructorArgument(Type type, Func callback); @@ -103,7 +103,7 @@ public interface IBindingWithSyntax : IBindingSyntax /// Indicates that the specified constructor argument should be overridden with the specified value. /// /// Specifies the argument type to override. - /// The callback to invoke to get the value for the argument. + /// The callback to invoke to get the value for the argument. /// The fluent syntax. IBindingWithOrOnSyntax WithConstructorArgument(Func callback); diff --git a/src/Ninject/Syntax/IConstructorArgumentSyntax.cs b/src/Ninject/Syntax/IConstructorArgumentSyntax.cs index 21f27f62..40fa1cb3 100644 --- a/src/Ninject/Syntax/IConstructorArgumentSyntax.cs +++ b/src/Ninject/Syntax/IConstructorArgumentSyntax.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,7 +19,7 @@ // See the License for the specific language governing permissions and // limitations under the License. // -//------------------------------------------------------------------------------- +//------------------------------------------------------------------------------------------------- namespace Ninject.Syntax { diff --git a/src/Ninject/Syntax/IFluentSyntax.cs b/src/Ninject/Syntax/IFluentSyntax.cs index 4538de86..e953638e 100644 --- a/src/Ninject/Syntax/IFluentSyntax.cs +++ b/src/Ninject/Syntax/IFluentSyntax.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 System.ComponentModel; -#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.Syntax { + using System; + using System.ComponentModel; + /// /// A hack to hide methods defined on for IntelliSense /// on fluent interfaces. Credit to Daniel Cazzulino. @@ -32,28 +44,28 @@ public interface IFluentSyntax /// 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. /// - [EditorBrowsable(EditorBrowsableState.Never)] + [EditorBrowsable(EditorBrowsableState.Never)] int GetHashCode(); /// - /// Returns a that represents this instance. + /// Returns a that represents this instance. /// /// - /// A that represents this instance. + /// A that represents this instance. /// - [EditorBrowsable(EditorBrowsableState.Never)] + [EditorBrowsable(EditorBrowsableState.Never)] string ToString(); /// - /// Determines whether the specified is equal to this instance. + /// Determines whether the specified is equal to this instance. /// - /// The to compare with this instance. + /// The to compare with this instance. /// - /// true if the specified is equal to this instance; otherwise, false. + /// true if the specified is equal to this instance; otherwise, false. /// - [EditorBrowsable(EditorBrowsableState.Never)] + [EditorBrowsable(EditorBrowsableState.Never)] bool Equals(object other); } } \ No newline at end of file diff --git a/src/Ninject/Syntax/IResolutionRoot.cs b/src/Ninject/Syntax/IResolutionRoot.cs index b2eb74ad..6ceb0e38 100644 --- a/src/Ninject/Syntax/IResolutionRoot.cs +++ b/src/Ninject/Syntax/IResolutionRoot.cs @@ -1,22 +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.Activation; -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.Syntax { + using System; + using System.Collections.Generic; + using Ninject.Activation; + using Ninject.Parameters; + using Ninject.Planning.Bindings; + /// /// Provides a path to resolve instances. /// @@ -28,7 +40,7 @@ public interface IResolutionRoot : IFluentSyntax /// The instance to inject. /// The parameters to pass to the request. void Inject(object instance, params IParameter[] parameters); - + /// /// Determines whether the specified request can be resolved. /// @@ -45,7 +57,7 @@ public interface IResolutionRoot : IFluentSyntax /// True if the request can be resolved; otherwise, false. /// bool CanResolve(IRequest request, bool ignoreImplicitBindings); - + /// /// Resolves instances for the specified request. The instances are not actually resolved /// until a consumer iterates over the enumerator. diff --git a/src/Ninject/Syntax/ModuleLoadExtensions.cs b/src/Ninject/Syntax/ModuleLoadExtensions.cs index a124468e..e6ab296b 100644 --- a/src/Ninject/Syntax/ModuleLoadExtensions.cs +++ b/src/Ninject/Syntax/ModuleLoadExtensions.cs @@ -1,21 +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.Infrastructure; -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. +// +//------------------------------------------------------------------------------------------------- namespace Ninject { + using System.Reflection; + using Ninject.Modules; + /// /// Extension methods that enhance module loading. /// @@ -64,4 +74,4 @@ public static void Load(this IKernelConfiguration kernelConfiguration, params As } #endif } -} +} \ No newline at end of file diff --git a/src/Ninject/Syntax/ResolutionExtensions.cs b/src/Ninject/Syntax/ResolutionExtensions.cs index f09cacfa..353d3653 100644 --- a/src/Ninject/Syntax/ResolutionExtensions.cs +++ b/src/Ninject/Syntax/ResolutionExtensions.cs @@ -1,25 +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; -using System.Linq; -using Ninject.Activation; -using Ninject.Infrastructure; -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 { + using System; + using System.Collections.Generic; + using System.Diagnostics.Contracts; + using System.Linq; + using Ninject.Activation; + using Ninject.Infrastructure; + using Ninject.Parameters; + using Ninject.Planning.Bindings; + using Ninject.Syntax; + /// /// Extensions that enhance resolution of services. /// @@ -369,31 +382,31 @@ public static bool CanResolve(this IResolutionRoot root, Type service, Func constraint, IEnumerable parameters, bool isOptional, bool isUnique) { - Ensure.ArgumentNotNull(root, "root"); - Ensure.ArgumentNotNull(service, "service"); - Ensure.ArgumentNotNull(parameters, "parameters"); + Contract.Requires(root != null); + Contract.Requires(service != null); + Contract.Requires(parameters != null); - IRequest request = root.CreateRequest(service, constraint, parameters, isOptional, isUnique); + var request = root.CreateRequest(service, constraint, parameters, isOptional, isUnique); return root.CanResolve(request); } private static IEnumerable GetResolutionIterator(IResolutionRoot root, Type service, Func constraint, IEnumerable parameters, bool isOptional, bool isUnique) { - Ensure.ArgumentNotNull(root, "root"); - Ensure.ArgumentNotNull(service, "service"); - Ensure.ArgumentNotNull(parameters, "parameters"); + Contract.Requires(root != null); + Contract.Requires(service != null); + Contract.Requires(parameters != null); - IRequest request = root.CreateRequest(service, constraint, parameters, isOptional, isUnique); + var request = root.CreateRequest(service, constraint, parameters, isOptional, isUnique); return root.Resolve(request); } - + private static IEnumerable GetResolutionIterator(IResolutionRoot root, Type service, Func constraint, IEnumerable parameters, bool isOptional, bool isUnique, bool forceUnique) { - Ensure.ArgumentNotNull(root, "root"); - Ensure.ArgumentNotNull(service, "service"); - Ensure.ArgumentNotNull(parameters, "parameters"); + Contract.Requires(root != null); + Contract.Requires(service != null); + Contract.Requires(parameters != null); - IRequest request = root.CreateRequest(service, constraint, parameters, isOptional, isUnique); + var request = root.CreateRequest(service, constraint, parameters, isOptional, isUnique); request.ForceUnique = forceUnique; return root.Resolve(request); } @@ -415,4 +428,4 @@ private static T DoTryGetAndThrowOnInvalidBinding(IResolutionRoot root, Func< return GetResolutionIterator(root, typeof(T), constraint, parameters, true, true, true).Cast().SingleOrDefault(); } } -} +} \ No newline at end of file diff --git a/src/Ninject/project.json b/src/Ninject/project.json new file mode 100644 index 00000000..a53c0b59 --- /dev/null +++ b/src/Ninject/project.json @@ -0,0 +1,53 @@ +{ + "version": "4.0.0-beta-*", + "authors": [ "Nate Kohari (nate@enkari.com)", "Remo Gloor (remo.gloor@gmail.com)", "Ninject Contributors" ], + "description": "Ninject is a lightning-fast, ultra-lightweight dependency injector for .NET applications.", + "copyright": "2007-2009, Enkari, Ltd. 2009-2016, Ninject Contributors.", + "dependencies": { + "StyleCop.Analyzers": { + "type": "build", + "version": "1.0.0" + } + }, + "frameworks": { + "netstandard1.3": { + "buildOptions": { + "define": [ "CORE", "NO_MEMBERTYPE", "NO_CUSTOM_ATTRIBUTE_PROVIDER", "NO_PARTIAL_TRUST", "NO_ASSEMBLY_SCANNING", "NO_EXCEPTION_SERIALIZATION", "NO_THREADING" ] + }, + "dependencies": { + "NETStandard.Library": "1.6.0", + "System.ComponentModel": "4.0.1", + "System.Data.Common": "4.1.0", + "System.Diagnostics.Contracts": "4.0.1", + "System.Reflection.Emit.ILGeneration": "4.0.1", + "System.Reflection.Emit.Lightweight": "4.0.1", + "System.Reflection.Extensions": "4.0.1", + "System.Reflection.TypeExtensions": "4.1.0" + } + }, + "netstandard1.5": { + "buildOptions": { + "define": [ "CORE", "NO_PARTIAL_TRUST", "NO_ASSEMBLY_SCANNING", "NO_EXCEPTION_SERIALIZATION", "NO_THREADING" ] + }, + "dependencies": { + "NETStandard.Library": "1.6.0", + "System.ComponentModel": "4.0.1", + "System.Data.Common": "4.1.0", + "System.Diagnostics.Contracts": "4.0.1", + "System.Reflection.Emit.ILGeneration": "4.0.1", + "System.Reflection.Emit.Lightweight": "4.0.1", + "System.Reflection.Extensions": "4.0.1", + "System.Reflection.TypeExtensions": "4.1.0" + } + }, + "net45": { + "buildOptions": { + "define": [ "NO_PARTIAL_TRUST" ] + } + } + }, + "buildOptions": { + "xmlDoc": true, + "additionalArguments": [ "/additionalfile:stylecop.json" ] + } +} \ No newline at end of file diff --git a/src/Ninject/stylecop.json b/src/Ninject/stylecop.json new file mode 100644 index 00000000..752ff92a --- /dev/null +++ b/src/Ninject/stylecop.json @@ -0,0 +1,12 @@ +{ + "$schema": "https://raw.githubusercontent.com/DotNetAnalyzers/StyleCopAnalyzers/master/StyleCop.Analyzers/StyleCop.Analyzers/Settings/stylecop.schema.json", + "settings": { + "documentationRules": { + "companyName": "Ninject Project Contributors", + "copyrightText": " Copyright (c) 2007-2010, Enkari, Ltd.\r\n Copyright (c) 2010-2016, Ninject Project Contributors\r\n Authors: Nate Kohari (nate@enkari.com)\r\n Remo Gloor (remo.gloor@gmail.com)\r\n\r\n Dual-licensed under the Apache License, Version 2.0, and the Microsoft Public License (Ms-PL).\r\n you may not use this file except in compliance with one of the Licenses.\r\n You may obtain a copy of the License at\r\n\r\n http://www.apache.org/licenses/LICENSE-2.0\r\n or\r\n http://www.microsoft.com/opensource/licenses.mspx\r\n\r\n Unless required by applicable law or agreed to in writing, software\r\n distributed under the License is distributed on an \"AS IS\" BASIS,\r\n WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r\n See the License for the specific language governing permissions and\r\n limitations under the License." + }, + "layoutRules": { + "newlineAtEndOfFile": "omit" + } + } +} \ No newline at end of file diff --git a/src/SharedAssemblyInfo.cs b/src/SharedAssemblyInfo.cs index 0d4fdd14..9a437c9e 100644 --- a/src/SharedAssemblyInfo.cs +++ b/src/SharedAssemblyInfo.cs @@ -1,24 +1,34 @@ +//------------------------------------------------------------------------------------------------- +// +// 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. +// +//------------------------------------------------------------------------------------------------- + using System; using System.Reflection; using System.Runtime.InteropServices; -//------------------------------------------------------------------------------ -// -// This code was generated by a tool. -// Runtime Version:4.0.30319.34011 -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - [assembly: AssemblyProductAttribute("Ninject: Lightweight dependency injection for .NET")] [assembly: AssemblyCompanyAttribute("Ninject Project Contributors")] -[assembly: AssemblyCopyrightAttribute("Copyright © 2007-2014 Ninject Project Contributors and contributors")] +[assembly: AssemblyCopyrightAttribute("Copyright 2007-2016 Ninject Project Contributors")] [assembly: AssemblyVersionAttribute("4.0.0.0")] [assembly: AssemblyFileVersionAttribute("4.0.0.6")] -#if !PCL [assembly: ComVisibleAttribute(false)] -#endif -[assembly: CLSCompliantAttribute(true)] - +[assembly: CLSCompliantAttribute(true)] \ No newline at end of file diff --git a/src/TestAssembly/TestAssembly.WinRT.csproj b/src/TestAssembly/TestAssembly.WinRT.csproj deleted file mode 100644 index f3e9a1fa..00000000 --- a/src/TestAssembly/TestAssembly.WinRT.csproj +++ /dev/null @@ -1,52 +0,0 @@ - - - - Debug - AnyCPU - 8.0.30703 - 2.0 - {E02E7007-D499-45FC-A48D-1C195DB58021} - Library - Properties - Ninject.Tests.TestAssembly - Ninject.Tests.TestAssembly - en-US - 512 - {BC8A1FFA-BEE3-4634-8014-F334798102B3};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC} - 8.1 - 12 - - - - true - full - false - bin\WinRT\Debug\ - DEBUG;TRACE - prompt - 4 - - - pdbonly - true - bin\WinRT\Release\ - TRACE - prompt - 4 - - - - - - - - - - - \ No newline at end of file diff --git a/src/TestAssembly/TestAssembly.csproj b/src/TestAssembly/TestAssembly.csproj deleted file mode 100644 index a0b98927..00000000 --- a/src/TestAssembly/TestAssembly.csproj +++ /dev/null @@ -1,76 +0,0 @@ - - - - Debug - AnyCPU - 9.0.30729 - 2.0 - {C9F6CFE7-44B2-4D55-9307-33C34C045468} - Library - Properties - Ninject.Tests.TestAssembly - Ninject.Tests.TestAssembly - v4.0 - 512 - - - 3.5 - - - publish\ - true - Disk - false - Foreground - 7 - Days - false - false - true - 0 - 1.0.0.%2a - false - false - true - - - true - full - false - ..\..\build\debug\ - DEBUG;TRACE - prompt - 4 - AllRules.ruleset - - - pdbonly - true - ..\..\build\release\ - TRACE - prompt - 4 - AllRules.ruleset - - - bin\AutomatedRelease\ - TRACE - true - pdbonly - AnyCPU - prompt - AllRules.ruleset - - - - - - - - \ No newline at end of file diff --git a/src/TestAssembly/TestAssembly.xproj b/src/TestAssembly/TestAssembly.xproj new file mode 100644 index 00000000..a5a03615 --- /dev/null +++ b/src/TestAssembly/TestAssembly.xproj @@ -0,0 +1,19 @@ + + + + 14.0 + $(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion) + + + + c9f6cfe7-44b2-4d55-9307-33c34c045468 + TestAssembly + .\obj + .\bin\ + v4.5.2 + + + 2.0 + + + \ No newline at end of file diff --git a/src/TestAssembly/project.json b/src/TestAssembly/project.json new file mode 100644 index 00000000..5d7d23c3 --- /dev/null +++ b/src/TestAssembly/project.json @@ -0,0 +1,10 @@ +{ + "version": "1.0.0-*", + "buildOptions": { + "outputName": "Ninject.Tests.TestAssembly" + }, + "frameworks": { + "net45": { + } + } +} \ No newline at end of file diff --git a/src/TestModules/TestModules.WinRT.csproj b/src/TestModules/TestModules.WinRT.csproj deleted file mode 100644 index 638cc049..00000000 --- a/src/TestModules/TestModules.WinRT.csproj +++ /dev/null @@ -1,55 +0,0 @@ - - - - Debug - AnyCPU - 8.0.30703 - 2.0 - {875065AA-EA3B-4C7A-B7DD-9B660AA76D27} - Library - Properties - Ninject.Tests.TestModules - Ninject.Tests.TestModule - en-US - 512 - {BC8A1FFA-BEE3-4634-8014-F334798102B3};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC} - 8.1 - 12 - - - - true - full - false - bin\WinRT\Debug\ - DEBUG;TRACE - prompt - 4 - - - pdbonly - true - bin\WinRT\Release\ - TRACE - prompt - 4 - - - - - - - - {0ea44209-1324-4bee-a8d2-46163d26b504} - Ninject.WinRT - - - - - \ No newline at end of file diff --git a/src/TestModules/TestModules.csproj b/src/TestModules/TestModules.csproj deleted file mode 100644 index 4912337b..00000000 --- a/src/TestModules/TestModules.csproj +++ /dev/null @@ -1,83 +0,0 @@ - - - - Debug - AnyCPU - 9.0.30729 - 2.0 - {90F46524-0716-4180-8A5F-1CD1EB5686F6} - Library - Properties - Ninject.Tests.TestModules - Ninject.Tests.TestModule - v4.5.1 - 512 - - - 3.5 - - - publish\ - true - Disk - false - Foreground - 7 - Days - false - false - true - 0 - 1.0.0.%2a - false - false - true - - - true - full - false - ..\..\build\debug\ - DEBUG;TRACE - prompt - 4 - AllRules.ruleset - false - - - pdbonly - true - ..\..\build\release\ - TRACE - prompt - 4 - AllRules.ruleset - false - - - bin\AutomatedRelease\ - TRACE - true - pdbonly - AnyCPU - prompt - AllRules.ruleset - false - - - - - - - - - - - - {ADF369E2-6B9E-4D56-9B82-D273AE41EC2D} - Ninject - False - - - - \ No newline at end of file diff --git a/src/TestModules/TestModules.sln b/src/TestModules/TestModules.sln deleted file mode 100644 index 32cc5552..00000000 --- a/src/TestModules/TestModules.sln +++ /dev/null @@ -1,31 +0,0 @@ - -Microsoft Visual Studio Solution File, Format Version 10.00 -# Visual Studio 2008 -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "TestModules", "TestModules.csproj", "{90F46524-0716-4180-8A5F-1CD1EB5686F6}" -EndProject -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Ninject", "..\Ninject\Ninject.csproj", "{ADF369E2-6B9E-4D56-9B82-D273AE41EC2D}" -EndProject -Global - GlobalSection(SolutionConfigurationPlatforms) = preSolution - AutomatedRelease|Any CPU = AutomatedRelease|Any CPU - Debug|Any CPU = Debug|Any CPU - Release|Any CPU = Release|Any CPU - EndGlobalSection - GlobalSection(ProjectConfigurationPlatforms) = postSolution - {90F46524-0716-4180-8A5F-1CD1EB5686F6}.AutomatedRelease|Any CPU.ActiveCfg = Release|Any CPU - {90F46524-0716-4180-8A5F-1CD1EB5686F6}.AutomatedRelease|Any CPU.Build.0 = 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 - {ADF369E2-6B9E-4D56-9B82-D273AE41EC2D}.AutomatedRelease|Any CPU.ActiveCfg = AutomatedRelease|Any CPU - {ADF369E2-6B9E-4D56-9B82-D273AE41EC2D}.AutomatedRelease|Any CPU.Build.0 = AutomatedRelease|Any CPU - {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}.Release|Any CPU.ActiveCfg = Release|Any CPU - {ADF369E2-6B9E-4D56-9B82-D273AE41EC2D}.Release|Any CPU.Build.0 = Release|Any CPU - EndGlobalSection - GlobalSection(SolutionProperties) = preSolution - HideSolutionNode = FALSE - EndGlobalSection -EndGlobal diff --git a/src/TestModules/TestModules.xproj b/src/TestModules/TestModules.xproj new file mode 100644 index 00000000..8d70589a --- /dev/null +++ b/src/TestModules/TestModules.xproj @@ -0,0 +1,19 @@ + + + + 14.0 + $(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion) + + + + 90f46524-0716-4180-8a5f-1cd1eb5686f6 + Ninject.Tests.TestModules + .\obj + .\bin\ + v4.5.2 + + + 2.0 + + + \ No newline at end of file diff --git a/src/TestModules/project.json b/src/TestModules/project.json new file mode 100644 index 00000000..ae3e387f --- /dev/null +++ b/src/TestModules/project.json @@ -0,0 +1,13 @@ +{ + "version": "1.0.0-*", + "dependencies": { + "Ninject": "3.2.5-beta" + }, + "buildOptions": { + "outputName": "Ninject.Tests.TestModule" + }, + "frameworks": { + "net45": { + } + } +} \ No newline at end of file