Search the web
Sign In
New User? Sign Up
PittsburghAltNet
? Already a member? Sign in to Yahoo!

Yahoo! Groups Tips

Did you know...
Show off your group to the world. Share a photo of your group with us.

Best of Y! Groups

   Check them out and nominate your group.
Having problems with message search? Fill out this form to ensure your group is one of the first to be migrated to the new message search system.

Messages

  Messages Help
Advanced
June meeting   Message List  
Reply | Forward Message #245 of 272 |
Re: [PittsburghAltNet] Re: June meeting

Very cool, thanks Jim.  Autofac is looking better every day :)

I actually "solved" my issue with doing something similar with Castle this morning by just working around it.  My issue that I mentioned in Friday's meeting was that we have two separate security contexts for our application (Online where the user has live access to the DB and Offline where the user just works against a local cache).  Since we only identify the security context at login (we don't support switching between online and offline during the same session) I simply register the appropriate context with the container at startup.  The psuedocode looks something like this...

if (IsOnline)
    _container.Register<ISecurityContext, OnlineSecurityContext>
else
    _container.Register<ISecurityContext, OfflineSecurityContext>

This works for us simply because we 'set it and forget it'.  If the security context could switch any time in the same session then this wouldn't work and we'd have to use something like we talked about during the meeting, but for us this does the trick (simplest thing that works, right?)

Here's a link to the article that explains how to do something similar to the Autofac solution below with Castle.  (I've never been able to get this example to work for me, though)
http://www.nablasoft.com/alkampfer/index.php/2007/05/19/windsor-container-resolveidictionary/

jeremy


On Wed, Jun 24, 2009 at 8:45 AM, Jim Bolla <yahoo@...> wrote:


One of the discussion points from the meeting was the scenario where you have a constructor where 1 or more parameters are to be injected and 1 or more parameters are to be supplied by the client code. I've been playing with Autofac a little bit and it has a really simple way to implement that. Here's my contrived example:

using System;

using Autofac;
using Autofac.Builder;

namespace AutofacTest
{
    internal class Program
    {
        private static void Main()
        {
            var builder = new ContainerBuilder();

            builder.Register<ConsoleLogger>().As<ILogger>();
            builder.Register<LogCommand>();
            builder.RegisterGeneratedFactory<LogCommandFactory>(new TypedService(typeof (LogCommand)));
            builder.Register<HelloWorldThreeTimes>();

            using (var container = builder.Build())
            {
                var helloWord = container.Resolve<HelloWorldThreeTimes>();
                helloWord.Run();
            }
        }
    }

    internal class HelloWorldThreeTimes
    {
        private readonly LogCommandFactory commandFactory;

        public HelloWorldThreeTimes(LogCommandFactory commandFactory)
        {
            this.commandFactory = commandFactory;
        }

        public void Run()
        {
            var command = commandFactory("Hello World.", 3);
            command.Run();
        }
    }

    internal delegate LogCommand LogCommandFactory(string message, int repeat);

    internal class LogCommand
    {
        private readonly ILogger logger;
        private readonly string message;
        private readonly int repeat;

        public LogCommand(string message, int repeat, ILogger logger)
        {
            this.message = message;
            this.repeat = repeat;
            this.logger = logger;
        }

        public void Run()
        {
            for (var i = 0; i < repeat; i++)
                logger.Info(message);
        }
    }

    internal interface ILogger
    {
        void Info(string message);
    }

    internal class ConsoleLogger : ILogger
    {
        public void Info(string message)
        {
            Console.WriteLine(message);
        }
    }
}


Using the RegisterGeneratedFactory() method to register a delegate as a factory method. Notice the LogCommandFactory takes 2 parameters while the LogCommand's constructor takes 3. Autofac glues them together automagically. Sweet.





--
Jeremy Jarrell
www.JeremyJarrell.com


Wed Jun 24, 2009 10:00 pm

jeremyjarrell
Offline Offline
Send Email Send Email

Forward
Message #245 of 272 |
Expand Messages Author Sort by Date

Hi everyone- So who's up for keeping the momentum going and having a June meeting? Do we want to have another midday meeting or an evening happy hour meeting?...
Matt Otto
matthew.otto
Offline Send Email
May 11, 2009
3:13 pm

I'm game. I don't have any topic in mind off hand, but i'd like to stick to the formal presentation style. What do you guys think? ... -- Jeremy Jarrell ...
Jeremy Jarrell
jeremyjarrell
Offline Send Email
May 12, 2009
4:00 pm

I like having an official/formal topic to be presented/discussed as the main event with any extra time at the end open to free-for-all. I think we're more...
Jim Bolla
crowdozer
Offline Send Email
May 12, 2009
4:57 pm

Ok, I liked the presentation based format as well, I just wanted to throw those questions out there to try and gauge feedback. As far as time is concerned I'm...
matt otto
matthew.otto
Offline Send Email
May 13, 2009
9:20 pm

you guys have any thoughts about a topic? would there be any interest in mocking (rhino mocks) or IoC (castle) or would that be too basic for us? ... -- Jeremy...
Jeremy Jarrell
jeremyjarrell
Offline Send Email
May 23, 2009
7:28 pm

I'd be ok with either of those topics. On Sat, May 23, 2009 at 3:27 PM, Jeremy Jarrell...
matt otto
matthew.otto
Offline Send Email
May 26, 2009
1:02 pm

I've never used Castle so that'd be interesting....
Jim Bolla
crowdozer
Offline Send Email
May 26, 2009
1:25 pm

OK, so how does a presentation on Castle/IoC on June 16th, from noon - 2PM at the Tech Council sound? jeremy ... -- Jeremy Jarrell www.JeremyJarrell.com...
Jeremy Jarrell
jeremyjarrell
Offline Send Email
May 29, 2009
12:03 pm

I'm in. On Fri, May 29, 2009 at 8:02 AM, Jeremy Jarrell...
matt otto
matthew.otto
Offline Send Email
May 29, 2009
12:11 pm

OK, i've sent a request in to the tech council for a room on June 16th. Our contact is out for the week but she'll be in next week so i'm going to hold off on...
Jeremy Jarrell
jeremyjarrell
Offline Send Email
Jun 1, 2009
4:42 pm

OK, quick update. We actually have to move this to Friday, June 19th due to a room conflict at the council. Otherwise, same bat time (Noon - 2), same bat...
Jeremy Jarrell
jeremyjarrell
Offline Send Email
Jun 1, 2009
6:41 pm

Sounds good. I think we should ask for RSVPs since the meeting rooms there are of a smallish size. Maybe I'm being optimistic about attendance. :)...
Jim Bolla
crowdozer
Offline Send Email
Jun 1, 2009
8:04 pm

Already on it - I have an EventBrite account set up. Going to add it to the site when I get a chance....
matt otto
matthew.otto
Offline Send Email
Jun 1, 2009
8:08 pm

OK, I posted the meeting to both our list and the main ALT.NET mailing list. I also added the dates to our group calendar, the wiki, and put it on event...
Jeremy Jarrell
jeremyjarrell
Offline Send Email
Jun 2, 2009
4:21 pm

I've uploaded the slides and code to the wiki page here... ...
jeremyjarrell
Offline Send Email
Jun 20, 2009
1:44 am

Thanks Jeremy. Great presentation. It definitely sparked some provoking conversion on the car ride home....
Jim Bolla
crowdozer
Offline Send Email
Jun 22, 2009
12:40 pm

One of the discussion points from the meeting was the scenario where you have a constructor where 1 or more parameters are to be injected and 1 or more...
Jim Bolla
crowdozer
Offline Send Email
Jun 24, 2009
12:46 pm

Very cool, thanks Jim. Autofac is looking better every day :) I actually "solved" my issue with doing something similar with Castle this morning by just...
Jeremy Jarrell
jeremyjarrell
Offline Send Email
Jun 24, 2009
10:01 pm
Advanced

Copyright © 2009 Yahoo! Inc. All rights reserved.
Privacy Policy - Terms of Service - Guidelines - Help