you can refactorize your code in a plenty of different way and avoid the
generic hell:

public interface IDataContextProvider
{
    TDataContext GetDataContextFor<TEntity>();
}

public class DataContextProvider : IDataContextProvider
{
   public TDataContext GetDataContextFor<TEntity>()
   {
       //do some reflection magic whatever...
      //use a custom attribute on top of TEntity ...
      //options options options
   }
}

public class Repository<T> : IRepository<T>
{

   public Repository(IDataContextProvider dataContextProvider) { .... }

   public TEntity GetById<TEntity>()
   {
       var dataContext = dataContextProvider.GetDataContext<T>();
       return dataContext.............;
   }

  ....
}





2011/3/7 Rob <[email protected]>

> No, but there may be multiple sets of entities in a given application
> (ie 2 datacontext types). I haven't seen Mike's full implementation,
> but I'm guessing his IDataContextProvider is just a single method with
> return new CustomerDataContext() or something similar (use the
> container with perwebrequest lifestyle to create it). If you had 2
> data context classes in your application with his approach, you'd need
> to manually configure every Repository<T> to use the appropriate
> concrete IDataContextProvider. My approach doesn't require per
> repository configuration.
>
>
>
> On Mar 7, 2:40 pm, José F. Romaniello <[email protected]> wrote:
> > the same entity can be stored and retrieved from multiples datacontexts?
> >
> > 2011/3/7 Rob <[email protected]>
> >
> >
> >
> >
> >
> >
> >
> > > I've seen Mike's implementation before and it has the same issues.
> > > Notice his repository takes an IDataContextProvider. He probably has a
> > > concrete class that just returns a single data context instance,
> > > whereas I support multiple data context types in the same application.
> >
> > > I think it's clear at this point that there's no built in way to
> > > handle the scenario I need.
> >
> > > Thanks for all the help.
> >
> > > On Mar 7, 2:25 pm, José F. Romaniello <[email protected]> wrote:
> > > > 2011/3/7 Rob <[email protected]>
> >
> > > > > It's hard for me to separate out and I don't have the rights to
> paste
> > > > > it directly.
> >
> > > > Then, you can ask the person who own the rights how to refactorize
> it.
> >
> > > > Are you aware of any other repository pattern implementation
> >
> > > > > techniques for linq to sql?
> >
> > > > I've never used Linq To Sql but the first google search return a
> > > meaningful
> > > > implementation:
> > >http://mikehadlow.blogspot.com/2008/03/using-irepository-pattern-with.
> ..
> > > > IRepository<T> implemented by Repository<T>
> > > > BTW; guess what, it seems to be free!
> >
> > > > To register this class the only thing you need to do is:
> >
> > >
> Container.Register(Component.For(typeof(IRepository<>)).ImplementedBy(typeo
> > > f(Repository<>));
> > > > as i told you in one of my mails.
> >
> > > --
> > > You received this message because you are subscribed to the Google
> Groups
> > > "Castle Project Users" group.
> > > To post to this group, send email to
> [email protected]
> > > .
> > > To unsubscribe from this group, send email to
> > > [email protected].
> > > For more options, visit this group at
> > >http://groups.google.com/group/castle-project-users?hl=en.
>
> --
> You received this message because you are subscribed to the Google Groups
> "Castle Project Users" group.
> To post to this group, send email to [email protected]
> .
> To unsubscribe from this group, send email to
> [email protected].
> For more options, visit this group at
> http://groups.google.com/group/castle-project-users?hl=en.
>
>

-- 
You received this message because you are subscribed to the Google Groups 
"Castle Project Users" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/castle-project-users?hl=en.

Reply via email to