Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Windows Froms Docs Don't Work #723

Open
matt-lethargic opened this issue Jun 7, 2019 · 1 comment

Comments

Projects
None yet
2 participants
@matt-lethargic
Copy link

commented Jun 7, 2019

Describe the bug
When following the Windows Forms Integration Guide I get lifestyle exception

Expected behavior
It just works

Actual behavior
Exception thrown on .Verify

The configuration is invalid. The following diagnostic warnings were reported:
-[Disposable Transient Component] MainForm is registered as transient, but implements IDisposable.
See the Error property for detailed information about the warnings. Please see https://simpleinjector.org/diagnostics how to fix problems and how to suppress individual warnings.

To Reproduce
Follow integration guide to the letter

leaving out

container.Register<IUserRepository, SqlUserRepository>(Lifestyle.Singleton);
container.Register<IUserContext, WinFormsUserContext>();
@dotnetjunkie

This comment has been minimized.

Copy link
Collaborator

commented Jun 7, 2019

You can follow this guide and ignore the warning as follows:

container.RegisterForm<Form1>();
container.RegisterForm<Form2>();
container.RegisterForm<Form3>();

// Where RegisterForm is the following extension method:
public static void RegisterForm<TForm>(this Container container) where TForm : Form
{
    var registration = Lifestyle.Transient.CreateRegistration<TForm>(container);
    container.AddRegistration(typeof(TForm), registration);
    registration.SuppressDiagnosticWarning(DiagnosticType.DisposableTransientComponent);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.