dimanche 29 mars 2015

Desktop Application Dependency Injection with Unity

I've used unity with MVC Web App. and in MVC we there is app_start method. and we use



DependencyResolver.SetResolver(new UnityDependencyResolver(container));


and this send the parameters to the Controller Constructor. now i am trying to find how to implement this pattern to DesktopApplication.


u guys know that we use new Form1().Show(); //bla bla foo and when i create a new form is it possible to do when i created a new instance of type of System.Windows.Forms it automatically send the parameters to the constructor.


Sorry for my language. now i am using something like this and asking if it's a better solution:



public partial class frm_FirmaSecimi : XtraForm
{
private IFirmaService _firmaService;

public frm_FirmaSecimi()
{
InitializeComponent();
_firmaService = UnityConfig.Container.Resolve<IFirmaService>();
}
}


is there a way to turn this in to:



public partial class frm_FirmaSecimi : XtraForm
{
private IFirmaService _firmaService;

public frm_FirmaSecimi(IFirmaService firmaService)
{
InitializeComponent();
_firmaService = firmaService;
}
}


this is a DevExpress Form by the way. Thanx for answers.


Aucun commentaire:

Enregistrer un commentaire