winform repository unityofwork autofac

449 views
Skip to first unread message

miche...@gmail.com

unread,
Jul 6, 2015, 10:43:55 AM7/6/15
to aut...@googlegroups.com
Hi All!

i'm trying to use autofac in winform application, i can read records but i can't add or update record. no error is generated but add and update doesn't work.

in the program.cs i put :

[STAThread]
static void Main()
{
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);

var builder = new ContainerBuilder();

builder.RegisterType<SisalWorkFlow.Infrastructure.DatabaseFactory>().AsImplementedInterfaces().InstancePerDependency();

builder.RegisterType<SisalWorkFlow.Infrastructure.UnitOfWork>().AsImplementedInterfaces().InstancePerDependency();

builder.RegisterType<SisalWorkFlow.Data.ReadOnly.Repository.SisalMasterRepository>().As<SisalWorkFlow.Data.ReadOnly.Repository.ISisalMasterRepository>();
builder.RegisterType<SisalWorkFlow.Service.Services4Read.SisalMasterService>().As<SisalWorkFlow.Service.Services4Read.ISisalMasterService>();

builder.RegisterType<SisalWorkFlow.Data.Repository.SisalMasterRepository>().As<SisalWorkFlow.Data.Repository.ISisalMasterRepository>();
builder.RegisterType<SisalWorkFlow.Service.SisalMasterService>().As<SisalWorkFlow.Service.ISisalMasterService>();

builder.Register(f => new MDIParent1(f.Resolve<SisalWorkFlow.Service.Services4Read.ISisalMasterService>()
, f.Resolve<SisalWorkFlow.Service.ISisalMasterService>())).As<MDIParent1>();

using (var container = builder.Build())
{
Application.Run(container.Resolve<MDIParent1>());
}

}


into the MDIParent1.cs i put

public partial class MDIParent1 : Form
{
private int childFormNumber = 0;
Service.Services4Read.ISisalMasterService _sisalMasterReadOnlyService;
Service.ISisalMasterService _sisalMasterService;

public MDIParent1(Service.Services4Read.ISisalMasterService sisalMasterReadOnlyService, Service.ISisalMasterService sisalMasterService)
//public MDIParent1()
{
InitializeComponent();
_sisalMasterReadOnlyService = sisalMasterReadOnlyService;
_sisalMasterService = sisalMasterService;
}


private void elencoToolStripMenuItem_Click(object sender, EventArgs e)
{
Lavorazioni _lavorazioni = new Lavorazioni(_sisalMasterReadOnlyService);
// Set the Parent Form of the Child window.
_lavorazioni.MdiParent = this;
// Display the new form.
_lavorazioni.Show();
}

private void creaToolStripMenuItem_Click(object sender, EventArgs e)
{
CreaLavorazione _creaLavorazione = new CreaLavorazione(_sisalMasterService);
// Set the Parent Form of the Child window.
_creaLavorazione.MdiParent = this;
// Display the new form.
_creaLavorazione.Show();
}


into the form that add record:

public partial class CreaLavorazione : Form
{
Service.ISisalMasterService _sisalMasterService;
public CreaLavorazione(Service.ISisalMasterService sisalMasterService)
{
InitializeComponent();
_sisalMasterService = sisalMasterService;
}

private void button1_Click(object sender, EventArgs e)
{
var _dm = new SisalMaster()
{
DataInserimento = DateTime.Now,
ID = 0,
Nota = txtNota.Text
};

_sisalMasterService.AddSisalMaster(_dm);
}


}


thanks in advance
Michele

Michael Powell

unread,
Jul 6, 2015, 12:22:58 PM7/6/15
to aut...@googlegroups.com, miche...@gmail.com


On Monday, July 6, 2015 at 10:43:55 AM UTC-4, miche...@gmail.com wrote:
Hi All!

i'm trying to use autofac in winform application, i can read records but i can't add or update record. no error is generated but add and update doesn't work.

If you can read, but can't add/update, then Autofac has done its work. This is an ORM question, not an Autofac question.
Reply all
Reply to author
Forward
0 new messages