Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
using System;
using System.ComponentModel.Composition;
using DryIoc;
using DryIoc.MefAttributedModel;
using NUnit.Framework;

namespace DryIoc.IssuesTests;

[TestFixture]
public class GHIssue710_ConstructorWithResolvableArguments_conflicts_with_Mef : ITest
{
public int Run()
{
Original_case();
return 1;
}

public interface IServer
{
void Hello();
}

public interface IPrinter
{
void Print(string s);
}

[Export(typeof(IServer))]
public class Server : IServer
{
[Import]
internal IPrinter Printer { get; set; }

public void Hello() => Printer.Print("Hello!");
}

[Export(typeof(IPrinter))]
public class Printer : IPrinter
{
public void Print(string s) => Console.WriteLine(s);
}

[Test]
public void Original_case()
{
var c = new Container().WithMef()
.With(rules => rules
.With(FactoryMethod.ConstructorWithResolvableArguments)
);

c.RegisterExports(typeof(Server), typeof(Printer));

var root = c.Resolve<IServer>();
Assert.That(root, Is.Not.Null, "Root is not resolved");

var server = root as Server;
Assert.That(server.Printer, Is.Not.Null, "Import is not satisfied");

root.Hello();
}
}
5 changes: 3 additions & 2 deletions test/DryIoc.TestRunner/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,8 @@ public static void RunAllTests()
Console.WriteLine("USE_COMPILATION_ONLY=true");
Rules.UnsafeResetDefaultRulesToUseCompilationOnly();
#endif
// note: @important to remember to do the Thread.Sleep in tests less that this setting,
// if you don't intentionally want the Error.WaitForScopedServiceIsCreatedTimeoutExpired exception,
// note: @important to remember to do the Thread.Sleep in tests less that this setting,
// if you don't intentionally want the Error.WaitForScopedServiceIsCreatedTimeoutExpired exception,
// e.g. see GHIssue337_Singleton_is_created_twice, GHIssue391_Deadlock_during_Resolve, Issue157_ContainerResolveFactoryIsNotThreadSafe
#if DEBUG
Scope.WaitForScopedServiceIsCreatedTimeoutMilliseconds = 2_000;
Expand Down Expand Up @@ -439,6 +439,7 @@ public static void RunAllTests()
new GHIssue669_Unable_to_resolve_type_with_optional_arguments_with_both_MefAttributedModel_and_MS_DI(),
new GHIssue678_Scope_is_lost_in_disposable_service(),
new GHIssue685_Creating_scopes_via_funcs_is_not_threadsafe_and_fails_sporadically_with_NullRef_exception(),
new GHIssue710_ConstructorWithResolvableArguments_conflicts_with_Mef(),
};

var totalPassed = 0;
Expand Down