Skip to content
This repository was archived by the owner on Jan 23, 2023. It is now read-only.
/ corefx Public archive

Add System.Composition #1851

Merged
merged 2 commits into from
Aug 21, 2015
Merged

Conversation

dsplaisted
Copy link
Member

This PR adds System.Composition to CoreFx.

System.Composition consists of 5 different assemblies:

  • System.Composition.AttributedModel
  • System.Composition.Convention
  • System.Composition.Hosting
  • System.Composition.Runtime
  • System.Composition.TypedParts

There is a general test project for all the assemblies, and another one specific to System.Composition.Convention. There are also two assemblies referenced by the general test project, and a project for perf testing.

I've created separate folders under /src for each of the five main assemblies, and put the general test project, the assemblies it references, and the perf test project in /src/System.Composition. I've put the solution file (System.Composition.sln) directly under /src.

I think this follows the current repository structure as closely as possible. Perhaps it makes more sense to put everything here under a System.Composition folder. Feedback is welcome.

Remaining issues

  • Are AssemblyInfo.cs files needed?
  • Remove unused usings?
  • Dependencies in project.json should be consistent with rest of repo (ie use "-beta-*")

Follow-up for after PR is merged

  • Clean up FEATURE_TRACING. #2991
  • Get rid of ReadLock type (discussion) #2995
  • Address commented out tests in ConventionBuilderTests.cs #3039
  • Add documentation around CompositionOperation, lifetime, and threading (discussion) #3040
  • Should strings in LifeTimeContext.ToString be localized?
  • Use Debug.Assert instead of Requires? (discussion)
  • Consider removing ExceptionBuilder (discussion)
  • Uncomment or delete commented out localizable attributes (discussion)

// Copyright (c) Microsoft. All rights reserved.
// Licensed under the MIT license. See LICENSE file in the project root for full license information.

using System.Resources;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Are such AssemblyInfo.cs files needed? I was under the impression that the buildtools supplied such attributes automatically.

@stephentoub
Copy link
Member

Lots of tests are failing, with errors like:

MESSAGE:
System.IO.FileNotFoundException : Could not load file or assembly 'System.Reflection.Emit.Lightweight, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a' or one of its dependencies. The system cannot find the file specified.
+++++++++++++++++++
STACK TRACE:
at System.Linq.Expressions.Compiler.LambdaCompiler..ctor(AnalyzedTree tree, LambdaExpression lambda) at System.Linq.Expressions.Compiler.LambdaCompiler.Compile(LambdaExpression lambda) at System.Linq.Expressions.Expression`1.Compile() at System.Composition.Hosting.Providers.Metadata.MetadataViewProvider.GetMetadataViewProvider[TMetadata]() in d:\j\workspace\dotnet_corefx_windows_debug_prtest\src\System.Composition.Hosting\src\System\Composition\Hosting\Providers\Metadata\MetadataViewProvider.cs:line 73 at System.Composition.Hosting.Providers.Lazy.LazyWithMetadataExportDescriptorProvider.GetLazyDefinitions[TValue,TMetadata](CompositionContract lazyContract, DependencyAccessor definitionAccessor) in d:\j\workspace\dotnet_corefx_windows_debug_prtest\src\System.Composition.Hosting\src\System\Composition\Hosting\Providers\Lazy\LazyWithMetadataExportDescriptorProvider.cs:line 32 at System.Composition.Hosting.Providers.Lazy.LazyWithMetadataExportDescriptorProvider.GetExportDescriptors(CompositionContract exportKey, DependencyAccessor definitionAccessor) in d:\j\workspace\dotnet_corefx_windows_debug_prtest\src\System.Composition.Hosting\src\System\Composition\Hosting\Providers\Lazy\LazyWithMetadataExportDescriptorProvider.cs:line 27 at System.Composition.Hosting.Core.ExportDescriptorRegistryUpdate.GetPromises(CompositionContract contract) in d:\j\workspace\dotnet_corefx_windows_debug_prtest\src\System.Composition.Hosting\src\System\Composition\Hosting\Core\ExportDescriptorRegistryUpdate.cs:line 148 at System.Composition.Hosting.Core.DependencyAccessor.TryResolveOptionalDependency(Object site, CompositionContract contract, Boolean isPrerequisite, CompositionDependency& dependency) in d:\j\workspace\dotnet_corefx_windows_debug_prtest\src\System.Composition.Hosting\src\System\Composition\Hosting\Core\DependencyAccessor.cs:line 64 at System.Composition.Hosting.Core.ExportDescriptorRegistryUpdate.Execute(CompositionContract contract) in d:\j\workspace\dotnet_corefx_windows_debug_prtest\src\System.Composition.Hosting\src\System\Composition\Hosting\Core\ExportDescriptorRegistryUpdate.cs:line 39 at System.Composition.Hosting.Core.ExportDescriptorRegistry.TryGetSingleForExport(CompositionContract exportKey, ExportDescriptor& defaultForExport) in d:\j\workspace\dotnet_corefx_windows_debug_prtest\src\System.Composition.Hosting\src\System\Composition\Hosting\Core\ExportDescriptorRegistry.cs:line 32 at System.Composition.Hosting.Core.LifetimeContext.TryGetExport(CompositionContract contract, Object& export) in d:\j\workspace\dotnet_corefx_windows_debug_prtest\src\System.Composition.Hosting\src\System\Composition\Hosting\Core\LifetimeContext.cs:line 197 at System.Composition.Hosting.CompositionHost.TryGetExport(CompositionContract contract, Object& export) in d:\j\workspace\dotnet_corefx_windows_debug_prtest\src\System.Composition.Hosting\src\System\Composition\Hosting\CompositionHost.cs:line 77 at System.Composition.CompositionContext.GetExport(CompositionContract contract) in d:\j\workspace\dotnet_corefx_windows_debug_prtest\src\System.Composition.Runtime\src\System\Composition\CompositionContext.cs:line 151 at System.Composition.CompositionContext.GetExport(Type exportType, String contractName) in d:\j\workspace\dotnet_corefx_windows_debug_prtest\src\System.Composition.Runtime\src\System\Composition\CompositionContext.cs:line 138 at System.Composition.CompositionContext.GetExport[TExport](String contractName) in d:\j\workspace\dotnet_corefx_windows_debug_prtest\src\System.Composition.Runtime\src\System\Composition\CompositionContext.cs:line 51 at System.Composition.CompositionContext.GetExport[TExport]() in d:\j\workspace\dotnet_corefx_windows_debug_prtest\src\System.Composition.Runtime\src\System\Composition\CompositionContext.cs:line 38 at System.Composition.UnitTests.MetadataTests.MultiplePiecesOfMetadataAreCombinedIntoAnArray() in d:\j\workspace\dotnet_corefx_windows_debug_prtest\src\System.Composition\tests\MetadataTests.cs:line 127MESSAGE:
System.IO.FileNotFoundException : Could not load file or assembly 'System.Reflection.Emit.Lightweight, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a' or one of its dependencies. The system cannot find the file specified.
+++++++++++++++++++
STACK TRACE:
at System.Linq.Expressions.Compiler.LambdaCompiler..ctor(AnalyzedTree tree, LambdaExpression lambda) at System.Linq.Expressions.Compiler.LambdaCompiler.Compile(LambdaExpression lambda) at System.Linq.Expressions.Expression`1.Compile() at System.Composition.Hosting.Providers.Metadata.MetadataViewProvider.GetMetadataViewProvider[TMetadata]() in d:\j\workspace\dotnet_corefx_windows_debug_prtest\src\System.Composition.Hosting\src\System\Composition\Hosting\Providers\Metadata\MetadataViewProvider.cs:line 73 at System.Composition.Hosting.Providers.Lazy.LazyWithMetadataExportDescriptorProvider.GetLazyDefinitions[TValue,TMetadata](CompositionContract lazyContract, DependencyAccessor definitionAccessor) in d:\j\workspace\dotnet_corefx_windows_debug_prtest\src\System.Composition.Hosting\src\System\Composition\Hosting\Providers\Lazy\LazyWithMetadataExportDescriptorProvider.cs:line 32 at System.Composition.Hosting.Providers.Lazy.LazyWithMetadataExportDescriptorProvider.GetExportDescriptors(CompositionContract exportKey, DependencyAccessor definitionAccessor) in d:\j\workspace\dotnet_corefx_windows_debug_prtest\src\System.Composition.Hosting\src\System\Composition\Hosting\Providers\Lazy\LazyWithMetadataExportDescriptorProvider.cs:line 27 at System.Composition.Hosting.Core.ExportDescriptorRegistryUpdate.GetPromises(CompositionContract contract) in d:\j\workspace\dotnet_corefx_windows_debug_prtest\src\System.Composition.Hosting\src\System\Composition\Hosting\Core\ExportDescriptorRegistryUpdate.cs:line 148 at System.Composition.Hosting.Core.DependencyAccessor.TryResolveOptionalDependency(Object site, CompositionContract contract, Boolean isPrerequisite, CompositionDependency& dependency) in d:\j\workspace\dotnet_corefx_windows_debug_prtest\src\System.Composition.Hosting\src\System\Composition\Hosting\Core\DependencyAccessor.cs:line 64 at System.Composition.Hosting.Core.ExportDescriptorRegistryUpdate.Execute(CompositionContract contract) in d:\j\workspace\dotnet_corefx_windows_debug_prtest\src\System.Composition.Hosting\src\System\Composition\Hosting\Core\ExportDescriptorRegistryUpdate.cs:line 39 at System.Composition.Hosting.Core.ExportDescriptorRegistry.TryGetSingleForExport(CompositionContract exportKey, ExportDescriptor& defaultForExport) in d:\j\workspace\dotnet_corefx_windows_debug_prtest\src\System.Composition.Hosting\src\System\Composition\Hosting\Core\ExportDescriptorRegistry.cs:line 32 at System.Composition.Hosting.Core.LifetimeContext.TryGetExport(CompositionContract contract, Object& export) in d:\j\workspace\dotnet_corefx_windows_debug_prtest\src\System.Composition.Hosting\src\System\Composition\Hosting\Core\LifetimeContext.cs:line 197 at System.Composition.Hosting.CompositionHost.TryGetExport(CompositionContract contract, Object& export) in d:\j\workspace\dotnet_corefx_windows_debug_prtest\src\System.Composition.Hosting\src\System\Composition\Hosting\CompositionHost.cs:line 77 at System.Composition.CompositionContext.GetExport(CompositionContract contract) in d:\j\workspace\dotnet_corefx_windows_debug_prtest\src\System.Composition.Runtime\src\System\Composition\CompositionContext.cs:line 151 at System.Composition.CompositionContext.GetExport(Type exportType, String contractName) in d:\j\workspace\dotnet_corefx_windows_debug_prtest\src\System.Composition.Runtime\src\System\Composition\CompositionContext.cs:line 138 at System.Composition.CompositionContext.GetExport[TExport](String contractName) in d:\j\workspace\dotnet_corefx_windows_debug_prtest\src\System.Composition.Runtime\src\System\Composition\CompositionContext.cs:line 51 at System.Composition.CompositionContext.GetExport[TExport]() in d:\j\workspace\dotnet_corefx_windows_debug_prtest\src\System.Composition.Runtime\src\System\Composition\CompositionContext.cs:line 38 at System.Composition.UnitTests.MetadataTests.MultiplePiecesOfMetadataAreCombinedIntoAnArray() in d:\j\workspace\dotnet_corefx_windows_debug_prtest\src\System.Composition\tests\MetadataTests.cs:line 127

/// </summary>
public class PartConventionBuilder
{
private readonly Type[] _emptyTypeArray = new Type[0];
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How about using Array.Empty<Type> at call sites instead of having this field?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@stephentoub This library targets platforms like .NET 4.5, Windows Store 8, and Windows Phone 8 which I don't think have support for Array.Empty<T>.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I see, I didn't realize these libraries weren't just .NET Core versions.

@stephentoub
Copy link
Member

Thanks, Daniel! Glad it's all building and almost ready to go. I'll re-review one more time once the remaining issues are addressed and it's squashed down (doesn't need to be a single commit, but it should be many fewer than 33, especially since many of those commits didn't build successfully).

@dsplaisted dsplaisted force-pushed the AddSystemComposition branch from 38aaa61 to 3bedf89 Compare August 8, 2015 02:50
@ghost
Copy link

ghost commented Aug 8, 2015

👍

<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
</PropertyGroup>
<ItemGroup>
<Compile Include="..\..\Common\src\Microsoft\Internal\Assumes.cs">
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

"..\..\Common\src" should be replaced with "$(CommonPath)"

@stephentoub
Copy link
Member

Regarding the remaining issues:

Are AssemblyInfo.cs files needed?

No.

Remove unused usings?

Ideally, but there are tons of unused usings across corefx as is. I'm ok with this being addressed separately and in a cleanup effort consistently across the repo.

Dependencies in project.json should be consistent with rest of repo (ie use "-beta-*")

At this point, stable dependencies no longer need "-beta-*".

@@ -0,0 +1,1185 @@
{
"locked": false,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Needs to be true

@stephentoub
Copy link
Member

Thanks, Daniel. Left a few more comments, but otherwise LGTM for the initial merge.

@dsplaisted
Copy link
Member Author

I've addressed all the feedback. I think @joshfree was of the opinion that when adding newly ported code, it should all be squashed down to one commit. Should I do so and then press the big green "merge" button?

@stephentoub
Copy link
Member

I think @joshfree was of the opinion that when adding newly ported code, it should all be squashed down to one commit. Should I do so and then press the big green "merge" button?

Personally I'd suggest squashing this down to two commits: one that covers your first three commits currently (initial code, formatting, building), and one that covers all of the subsequent cleanup you then did. The first commit would be from dotnet-bot, and the second commit would be from you. But if you feel there's a cleaner approach, maybe you feel some specific commit should be kept separate, etc., that's fine, too.

Once that's done and CI passes again, merge away.

@ghost
Copy link

ghost commented Aug 21, 2015

So now it is just a matter of squashing the commits and after that it will be merged? Yay! Love to see System.Composition getting merged into CoreFX! 🎆

Going by @stephentoub's suggestion and other "initial commit" PRs, it would probably be 1c3415a, 1f1d240, 63f15b5 and 62bc5bd fixed up to 5b5364c. And remaining squashed to a separate commit with bulleted list (* my message) of changes in the commit log.

Thanks for doing this @dsplaisted! 👌

dotnet-bot and others added 2 commits August 21, 2015 07:33
* Use ReaderWriterLockSlim
* Move duplicated code into common folder
* Use EmptyArray<T> instead of new T[0]
* Fix CLS Compliance error in System.Composition test library
  (See dotnet/roslyn#4293: CLS Compliance warning CS3016 is reported on
  non-public members)
* Rename SilverlightTraceWriter.cs to DebuggerTraceWriter.cs
* Use CommonPath build property to include common files
* Remove unnecessary AssemblyInfo.cs files
* Remove unused private constant in System.Composition.AttributedModel
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.