--
You received this message because you are subscribed to the Google Groups "Autofac" group.
To post to this group, send email to aut...@googlegroups.com.
To unsubscribe from this group, send email to autofac+u...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/autofac?hl=en.
Anyway, code follows. As I say, I'm not using it, but it works in my tests so far. I've moved away from using it how I thought I might as I'm not hugely liking highly concrete dependencies on an inheritance hierarchy, but I can imagine cases where it's worth it.
<code>
public class AutofacViewPageActivator : IViewPageActivator
{
private readonly IComponentContext context;
public AutofacViewPageActivator(IComponentContext context)
{
this.context = context;
}
public object Create(ControllerContext controllerContext, Type type)
{
var service = new TypedService(type);
if (!context.IsRegisteredService(service))
RegisterViewPageService(type);
return context.ResolveService(service);
}
private void RegisterViewPageService(Type serviceType)
{
var builder = new ContainerBuilder();
builder
.RegisterType(serviceType)
.PropertiesAutowired(false)
.InstancePerHttpRequest();
builder
.Update(context.ComponentRegistry);
}
}
</code>
Cheers,
A.
----- Start Original Message -----
Sent: Thu, 25 Nov 2010 06:28:01 -0800 (PST)
From: Alex Meyer-Gleaves <alex.mey...@gmail.com>
To: Autofac <aut...@googlegroups.com>
Subject: Re: MVC integration assembly name
> To unsubscribe from this group, send email to autofac+u...@googlegroups.com.
> For more options, visit this group at http://groups.google.com/group/autofac?hl=en.
----- End Original Message -----
I'd love something a bit more convention based but haven't a way. The framework will try IDependencyResolver for an IViewPageActivator first of all. If not found, it will try the concrete class of the view (something like ASP.Index_cshtml), and finally it'll go for Activator.CreateInstance.
The classes requested are pretty much "dynamic" they're created from the .cshtml for example in the case of Razor views. They implicitly inherit from WebViewPage, unless overridden, but they don't exist at compile time in terms of registerable types that I can see. Which leaves a common base out in the cold as well as far as I can see. If you override you must inherit with an abstract class and only a default constructor is possible.
It's a bit of a flaw in the compilation process for view pages as far as I'm concerned, but I can see why. One of those things. I couldn't find a much neater way of doing it without adding more complexity (which would be sensible for performance in some cases perhaps). If anyone has any thoughts, I'm totally open.
In terms of an IRegistrationSource, that sounds interesting - I'll go and look at the Autofac core code!
Cheers
A.
----- Start Original Message -----
Sent: Tue, 30 Nov 2010 08:00:37 +1000
From: Nicholas Blumhardt <nicholas....@gmail.com>
To: aut...@googlegroups.com
Subject: Re: MVC integration assembly name
> Hi Andrew,
>
> Thanks for the info! Couple of questions, if you or anyone on the list has
> the time to look at them:
>
>
> - Are there any criteria that identify View types; e.g. are they all
> derived from a common base, or have names that can be tested, such as ending
> with the word 'View'?
> - Will ASP.NET MVC try the IDependencyResolver before hitting the
> > <autofac%2Bunsu...@googlegroups.com<autofac%252Buns...@googlegroups.com>>
> > > > >> .
> > > > >> For more options, visit this group at
> > > > >>http://groups.google.com/group/autofac?hl=en.
> > > >
> > > > > --
> > > > > You received this message because you are subscribed to the Google
> > Groups
> > > > > "Autofac" group.
> > > > > To post to this group, send email to aut...@googlegroups.com.
> > > > > To unsubscribe from this group, send email to
> > > > > autofac+u...@googlegroups.com<autofac%2Bunsu...@googlegroups.com>
> > <autofac%2Bunsu...@googlegroups.com<autofac%252Buns...@googlegroups.com>>
> > > > > .
> > > > > For more options, visit this group at
> > > > >http://groups.google.com/group/autofac?hl=en.
> > >
> > > --
> > > You received this message because you are subscribed to the Google Groups
> > "Autofac" group.
> > > To post to this group, send email to aut...@googlegroups.com.
> > > To unsubscribe from this group, send email to
> > autofac+u...@googlegroups.com<autofac%2Bunsu...@googlegroups.com>
> > .
> > > For more options, visit this group at
> > http://groups.google.com/group/autofac?hl=en.
> >