Registering and Resolving a Service with delegate type constructor parameter using Structuremap

Solution 1:

I defined following Registry class in my WindowsForm project:

public class WinUIRegistry:Registry
{
    public WinUIRegistry()
    {
        bool SimpleQuestionDelegate(string question)
        {
            var questionForm = new SimpleQuestionForm();
            questionForm.SetData(question);
            return questionForm.ShowDialog() == DialogResult.Yes;
        }

        For<IService>()
            .Use<MyService>()
            .Ctor<Func<string, bool>>().Is(SimpleQuestionDelegate);
    }
}

And then added registry to the ObjectFactory's Container by following code in the start of the project's Program.cs:

ObjectFactory.Container.Configure(x=>x.IncludeRegistry<WinUIRegistry>()); 

For relosving:

var service = ObjectFactory.Container.GetInstance<IService>();