Click here to Skip to main content
15,897,518 members
Home / Discussions / C#
   

C#

 
GeneralRe: Drawing Text on Panel Pin
Danzy8315-Feb-12 2:10
Danzy8315-Feb-12 2:10 
GeneralRe: Drawing Text on Panel Pin
Pete O'Hanlon15-Feb-12 2:25
mvePete O'Hanlon15-Feb-12 2:25 
GeneralRe: Drawing Text on Panel Pin
BillWoodruff18-Feb-12 1:05
professionalBillWoodruff18-Feb-12 1:05 
AnswerRe: Drawing Text on Panel Pin
Montasser Ben Ouhida2-Mar-12 4:30
Montasser Ben Ouhida2-Mar-12 4:30 
QuestionHow to create method extensions but inject into them with IoC Pin
Gizz14-Feb-12 23:08
Gizz14-Feb-12 23:08 
AnswerRe: How to create method extensions but inject into them with IoC Pin
BobJanova14-Feb-12 23:24
BobJanova14-Feb-12 23:24 
GeneralRe: How to create method extensions but inject into them with IoC Pin
Gizz15-Feb-12 0:16
Gizz15-Feb-12 0:16 
GeneralRe: How to create method extensions but inject into them with IoC Pin
BobJanova15-Feb-12 0:38
BobJanova15-Feb-12 0:38 
Ah, okay, now I see the problem.

The easiest way is to register in reverse, i.e. pass a container to the extension class:
static class DateExtensions {
 static IUnityContainer container;
 static HolidayHandler handler;

 public static void RegisterHolidayHandler(IUnityContainer container){
  container.Register<HolidayHandler, HolidayHandler>();
  this.container = container;
 } 
 
 public static bool IsHoliday(){
  if(handler == null) handler = container.Resolve<HolidayHandler>();
  // etc
 }

 class HolidayHandler {
  internal List<Holidays> holidays;
  public HolidayHandler(EntityContext context){
   holidays = context.GetHolidays();
   // or however your lookup classes work
   // EntityContext can be got from IoC
  }
 }
}


If you want some syntactic tidyness then of course RegisterHolidayHandler can itself be an extension method.

If you don't want to have a dependency on the dependency injection framework here (and I don't think you do, really), you need to give the extension class a property (of type IHolidayHandler or something) and explicitly assign an instance of a subclass which is populated by IoC. This is essentially 'loading the holidays' but with the mechanics of it abstracted and hidden away. That is pretty much what you say you don't want to do.

I can't think of a clever way without having to do, at least,
DateExtensions.HolidayRepository = _container.Resolve<IHolidayRepository>();

GeneralRe: How to create method extensions but inject into them with IoC Pin
Gizz15-Feb-12 1:41
Gizz15-Feb-12 1:41 
GeneralRe: How to create method extensions but inject into them with IoC Pin
BobJanova15-Feb-12 1:58
BobJanova15-Feb-12 1:58 
QuestionGive me some Suggestions for Make a Editor like Word Pin
Marlai14-Feb-12 21:15
Marlai14-Feb-12 21:15 
AnswerRe: Give me some Suggestions for Make a Editor like Word Pin
thatraja14-Feb-12 21:36
professionalthatraja14-Feb-12 21:36 
Questionpso(particle swarm optimization) Pin
nasrin6614-Feb-12 21:01
nasrin6614-Feb-12 21:01 
Questioncapturing outward traffic Pin
saneehaAamir14-Feb-12 19:14
saneehaAamir14-Feb-12 19:14 
AnswerRe: capturing outward traffic Pin
Keith Barrow14-Feb-12 21:52
professionalKeith Barrow14-Feb-12 21:52 
QuestionAbout Reflecting and generics Pin
PozzaVecia14-Feb-12 11:06
PozzaVecia14-Feb-12 11:06 
AnswerRe: About Reflecting and generics Pin
Luc Pattyn14-Feb-12 11:19
sitebuilderLuc Pattyn14-Feb-12 11:19 
GeneralRe: About Reflecting and generics Pin
PozzaVecia14-Feb-12 11:42
PozzaVecia14-Feb-12 11:42 
AnswerRe: About Reflecting and generics Pin
Luc Pattyn14-Feb-12 12:08
sitebuilderLuc Pattyn14-Feb-12 12:08 
GeneralRe: About Reflecting and generics Pin
PozzaVecia14-Feb-12 12:29
PozzaVecia14-Feb-12 12:29 
AnswerRe: About Reflecting and generics Pin
Luc Pattyn14-Feb-12 12:41
sitebuilderLuc Pattyn14-Feb-12 12:41 
RantRe: About Reflecting and generics Pin
PozzaVecia14-Feb-12 12:58
PozzaVecia14-Feb-12 12:58 
GeneralRe: About Reflecting and generics Pin
GParkings14-Feb-12 23:44
GParkings14-Feb-12 23:44 
GeneralRe: About Reflecting and generics Pin
PozzaVecia15-Feb-12 0:10
PozzaVecia15-Feb-12 0:10 
GeneralRe: About Reflecting and generics Pin
GParkings15-Feb-12 0:59
GParkings15-Feb-12 0:59 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.