Featured post

c# - Usage of Server Side Controls in MVC Frame work -

i using asp.net 4.0 , mvc 2.0 web application. project requiremrnt have use server side control in application not possibl in noraml case. ideally want use adrotator control , datalist control. i saw few samples , references in codepleax mvc controllib howwver found less useful. can tell how utilize theese controls in asp.net application along mvc. note: please provide functionalities related adrotator , datalist controls not equivalent functionalities thanks in advace. mvc pages not use normal .net solution makes use of normal .net components impossible. a normal .net page use event driven solution call different methods service side mvc use actions , view completly different way handle things. also, mvc not use viewstate normal .net controlls require. found article discussing mixing of normal .net , mvc.

c# - How to implement a generic RepositoryFactory? -


i'm trying implement generic repository. i've got far ...

public interface irepositoryfactory {     irepository<t> repositoryof<t>() t : class; }  public class entityframeworkrepositoryfactory : irepositoryfactory {     private readonly iwindsorcontainer _container;      public entityframeworkrepositoryfactory(iwindsorcontainer container)     {         _container = container;     }      public irepository<t> repositoryof<t>() t : class     {         var repository = _container.resolve<irepository<t>>();         return repository;     } } 

the repositoryfactory used unit of work implementation

public interface iunitofwork : idisposable {     irepository<t> repositoryof<t>() t : class;     void commit(); } 

anyway, question want ask whether having repositoryfactory implementation depend on iwindsorcontainer correct?

i needed way of asking irepository of type, installer code ...

// windsor container container.register(     component.for<iwindsorcontainer>()         .named("container")         .instance(container)     ); 

which seems go against whole concept of ioc, maybe whole idea of asking repository anyway.

edit (as reply miensol's answer)

i using windsor create repositories me following code in installer ...

// generic repository container.register(     component.for(typeof (irepository<>))         .implementedby(typeof (entityframeworkrepository<>))         .serviceoverrides(             serviceoverride.forkey("objectcontext").eq("objectcontext"))     ); 

i have used servicelocator in past achieve want, have read it's bit of anti-pattern. trying avoid using it. although have admit i'm not sure why, i've done seems wrong bound using castle windsor ioc/di framework. service locator meant framework agnostic.

so, i'm bit confused!

i'm not entirely sure why need irepositoryfactory when using ioc framework. having dependencies specific ioc container implementations scattered though code base not idea. of time when really can't find way make container inject dependencies objects use service locator pattern, here can find commonly used implementation .net. factory method this:

public irepository<t> repositoryof<t>() t : class {   return servicelocator.current.getinstance<irepository<t>>(); } 

nevertheless seems make windsor create generic repository anyways:

container.register(   component.for(typeof(irepository<>)).implementedby(typeof(genericrepositoryimplementation<>)) ); 

and having them injected objects so:

public class classthatrequiressomerepos {   irepository<oneentity> repoone;   irepository<twoentity> repotwo;    public classthatrequiressomerepos(irepository<oneentity> oneentityrepository, irepository<twoentity> twoentityrepository)   {     _repoone = oneentityrepository;     _repotwo = twoentityrepository;   } }  

Comments

Popular posts from this blog

c# - Usage of Server Side Controls in MVC Frame work -

cocoa - Nesting arrays into NSDictionary object (Objective-C) -

ios - Very simple iPhone App crashes on UILabel settext -