inversion of control - How configure LightInject in ASP.NET MVC? -
i use simpleinjector in mvc code
public static class simpleinjectorinitializer { public static void initialize() { var container = new container(); initializecontainer(container); container.registermvccontrollers(assembly.getexecutingassembly()); container.verify(); dependencyresolver.setresolver(new simpleinjectordependencyresolver(container)); } private static void initializecontainer(container container) { container.register<ipersonrepository, personentityrepository>(); } }
but want test lightinject ioc in mvc application how ?
i wrote code
[assembly: webactivator.postapplicationstartmethod(typeof(lightinjectinitializer), "initializeli")] public static class lightinjectinitializer { public static void initializeli() { var container = new servicecontainer(); initializecontainer(container); container.registercontrollers(assembly.getexecutingassembly()); container.enablemvc(); } private static void initializecontainer(servicecontainer container) { container.register(typeof(personentityrepository), typeof(ipersonrepository), new perscopelifetime()); } }
but show me error
no parameterless constructor defined object.
can me writing equivalent code working in mvc ?
sample code : download
i author of lightinject , out.
this static initialize method? called from. reason error because initialize code did not execute.
if further assistance, valuable see have in global.asax.cs.
this page contains information how set up.
Comments
Post a Comment