-
Notifications
You must be signed in to change notification settings - Fork 54
Open
Description
I've registered my FormUserNew:
_container.Register<FormUsersNew>();
which is called from FormMain (starting form), however i am not sure how should i take instance of that in FormMain then call it.
Here's my code below:
static class Program
{
static void Main()
{
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
Bootstrap();
Application.Run(_container.GetInstance<FormMain>());
private static void Bootstrap()
{
_container = new Container();
_container.Options.DefaultScopedLifestyle = new ThreadScopedLifestyle();
_container.Register<IUserService, UserService>(Lifestyle.Scoped);
_container.Register<IUserTypeService, UserTypeService>(Lifestyle.Scoped);
_container.Register<FormMain>();
_container.Register<FormUsersNew>(); //<=========== form
_container.Verify();
}
}
FormUsersNew:
public partial class FormUsersNew
{
private readonly Sektor _sektor;
private readonly IUserService _userService;
private readonly IUserTypeService _userTypeService;
public FormUsersNew(IUserService userService, IUserTypeService userTypeService, EnumSector sector)
{
InitializeComponent();
_sektor = sektor;
_userService = userService;
_userTypeService = userTypeService;
}
How then to call FormUsersNew to use my dependencies from container? :
public partial class FormMain
{
private void BtnOpen_Click(object sender, EventArgs e)
{
//call FormUserNew from container <=======================
//var form = new FormUsersNew();
//form.ShowDialog();
}
}
Metadata
Metadata
Assignees
Labels
No labels