asp.net mvc 3 dependency injection ninject -
i want ask asp.net mvc 3 dependency injection ninject.
here interface,
public interface iregistration<t> { bool registration(t entity); }
this clsmembers class.
public class clsmembers:iregistration<member> { private smileworkdbentities db; public clsmembers() { db = new smileworkdbentities(); } public bool registration(member member) { db.members.add(member); if (db.savechanges() != 0) { return true; } else { return false; } } public int getmemberid(string username, string pwd) { var mem = (from m in db.members m.member_username == username && m.member_password == pwd select m).firstordefault(); return mem.member_id; } }
here controller,
public class membersregistrationcontroller : controller { iregistration<member> ireg1; public membersregistrationcontroller(iregistration<member> _ireg1) { ireg1 = _ireg1; } public actionresult memberregistration() { return view(); } [httppost] public actionresult memberregistration(member m) { if(ireg1.registration(m)) { return redirecttoaction("memberprofileregistration", new {mid = }); } else { return view(); } } }
everything ok... cannot access getmemberid() method.. pls tell me how can access getmemberid() controller...
regard, minthittun
modify iregistration
interface adding int getmemberid(string username, string pwd)
method:
public interface iregistration<t> { bool registration(t entity); int getmemberid(string username, string pwd); }
after all, thing should read interfaces (c# programming guide)
update:
public interface imembersrepository { int getmemberid(string username, string password); // other stuff related members... } public class membersrepository : imembersrepository { private smileworkdbentities db = new smileworkdbentities(); public int getmemberid(string username, string password) { var mem = (from m in db.members m.member_username == username && m.member_password == pwd select m).firstordefault(); return mem.member_id; } // other stuff related members... } public class membersregistrationcontroller : controller { iregistration<member> ireg1; imembersrepository membersrepository; public membersregistrationcontroller(iregistration<member> _ireg1, imembersrepository memrepository) { ireg1 = _ireg1; membersrepository = memrepository; } // ... }
Comments
Post a Comment