Skip to content

Commit 5e9c0bc

Browse files
committed
removing the old stuff from Mef wrapper and testing it
1 parent ccaa421 commit 5e9c0bc

File tree

2 files changed

+22
-5
lines changed

2 files changed

+22
-5
lines changed

src/DryIoc.MefAttributedModel/AttributedModel.cs

+1-4
Original file line numberDiff line numberDiff line change
@@ -137,17 +137,14 @@ public static IContainer WithMefSpecificWrappers(this IContainer container)
137137
made: _createExportFactoryMethod,
138138
setup: Setup.Wrapper);
139139

140-
// todo: @perf optimize to use unwrapped factory
140+
// todo: @perf optimize to use unwrapped factory the same as GetLazyMetadataExpressionOrDefault
141141
container.Register(typeof(ExportFactory<,>),
142142
made: _createExportFactoryWithMetadataMethod,
143143
setup: Setup.WrapperWith(0));
144144

145145
container.Register(typeof(Lazy<,>),
146146
WrapperExpressionFactory.Of(GetLazyMetadataExpressionOrDefault, Setup.WrapperWith(0)));
147147

148-
container.Register(typeof(Lazy<>),
149-
WrapperExpressionFactory.Of(WrappersSupport.GetLazyExpressionOrDefault), IfAlreadyRegistered.Replace);
150-
151148
return container;
152149
}
153150

test/DryIoc.IssuesTests/GHIssue228_Updated_DryIoc_from_4_to_4_1_in_Unity_Engine_project_keyed_register_resolve_wont_work_anymore.cs

+21-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
using System;
22
using System.Linq;
33
using DryIoc.ImTools;
4+
using DryIoc.MefAttributedModel;
45
using NUnit.Framework;
56

67
namespace DryIoc.IssuesTests
@@ -10,6 +11,9 @@ public class GHIssue228_Updated_DryIoc_from_4_to_4_1_in_Unity_Engine_project_key
1011
{
1112
public int Run()
1213
{
14+
// Mef Lazy<T, M> wrapper
15+
Test_the_metadata_with_LazyMeta_and_the_same_keys_But_only_one_key_matches_the_metadata();
16+
1317
Test_the_Func_metadata_and_the_Diff_keys_But_only_one_key_matches_the_metadata();
1418
Test_the_Func_metadata_and_the_same_keys_But_only_one_key_matches_the_metadata();
1519
Test_the_Lazy_metadata_and_the_Diff_keys_But_only_one_key_matches_the_metadata();
@@ -21,7 +25,8 @@ public int Run()
2125
Test_the_metadata_and_the_same_keys();
2226
For_multiple_same_key_registrations_all_should_be_returned();
2327
Should_be_able_to_get_two_keyed_registrations();
24-
return 11;
28+
29+
return 12;
2530
}
2631

2732
[Test]
@@ -190,6 +195,21 @@ public void Test_the_metadata_with_Lazy_and_the_same_keys_But_only_one_key_match
190195
Assert.AreEqual(42, ab[0].Metadata);
191196
}
192197

198+
[Test]
199+
public void Test_the_metadata_with_LazyMeta_and_the_same_keys_But_only_one_key_matches_the_metadata()
200+
{
201+
var container = new Container().WithMef();
202+
203+
container.Register<Iface, A>(serviceKey: Keys.A, setup: Setup.With(metadataOrFuncOfMetadata: "a"));
204+
container.Register<Iface, B>(serviceKey: Keys.A, setup: Setup.With(metadataOrFuncOfMetadata: 42));
205+
container.Register<Iface, C>(serviceKey: Keys.C, setup: Setup.With(metadataOrFuncOfMetadata: "c"));
206+
207+
var ab = container.Resolve<Lazy<Iface, int>[]>(serviceKey: Keys.A);
208+
Assert.AreEqual(1, ab.Length);
209+
Assert.IsInstanceOf<B>(ab[0].Value);
210+
Assert.AreEqual(42, ab[0].Metadata);
211+
}
212+
193213
[Test]
194214
public void Test_the_Func_metadata_and_the_Diff_keys_But_only_one_key_matches_the_metadata()
195215
{

0 commit comments

Comments
 (0)