I want to start using dependency injection in my WPF application, largely for better unit testability. My app is mostly constructed along the M-V-VM pattern.
I'm looking at autofac for my IoC container, but I don't think that matters too much for this disucssion.
Injecting a service into the start window seems straightforward, as I can...
The examples I can find use a two layer architecture, where the controllers directly use the repository classes in the data access layer. See here or here.
Where would you register components from the data access layer if you have a service or business logic layer that uses those components? The data access layer should ideally not be r...
I have the following code in an Autofac Module that is used in my Application_Start method:
builder.Register(c => new Configuration().Configure().BuildSessionFactory())
.SingletonScoped();
builder.Register(c => c.Resolve<ISessionFactory>().OpenSession())
.HttpRequestScoped();
builder.Register<NHibernateSomethingRepository>().As...
I'm trying to integrate Autofac into an exsisting ASP.NET web application.
The pages follow the MVP pattern. Each page implements a View and delegate functionality to a Presenter. The View is injected into the Presenter thru the constructor.
I was able to register the Presenter and View and the page loads fine but when a postback h...
I've been trying to integrate the latest version of autofac (1.3.3.54), and I'm running into the following problem.
The recommended way of consuming parameters in the Register callback, per the Google code wiki for the project is as follows:
builder.Register((c, p) => new Foo(p.Get("arg1")));
However this won't compile with the mentio...
I have some providers, say -
<Providers>
<Provider Type="Providers.IM" Name="Im"/>
<Provider Type="Providers.Web" Name="Web"/>
...
</Provider>
Each of these providers can give me a session :
<Sessions>
<Session Name="GoogleIM" Provider="Im" URL="..." />
<Session Name="YahooIM" Provider="Im" URL="..." />
<S...
I'm trying to configure nHibernate to use a MySql database. I found examples for mssql and sqlite but none for mysql.
So, how do I change this so it uses mysql:
Fluently.Configure().Database(
MsSqlConfiguration.MsSql2005.ConnectionString(
c => c.FromConnectionStringWithKey("ConnectionString")
)
)
.Map...
I'm still pretty new to using Autofac and one thing I miss in the documentation and examples is how to make it easy to get to the configured container from different places in a web application.
I know I can use the Autofac controller factory to automatically resolve constructor injected dependencies for controllers, but how about the ...
I've read about Autofac that it's fast. I've seen the coding involved and it's preatty neat. But I'm not quite sure how to use it. I've used StructureMap, and it has a static ObjectFactory. Ninject has the Kernel, but in autofac's google pages they recomend doing something like this :
using( var resolver = builder.Build() ){
var wh...
Hi
Context:
We are building a framework for rapid delivery of WPF applications. This framework uses Autofac as an IoC container and also uses regions from Prism v1. We are scheduling tasks with Parallel extensions from Microsoft.
We are facing the following problem:
When we boot the application with empty views (so just a shell with re...
I have been looking for a way to register a factory class in autofac using XmlConfiguration but the documentation seems a bit slim.
What I want to accomplish is to do the following in my configuration instead:
builder.Register(c => MyFactory.GetMyObject()).As<IMyObject>();
Are there any good way of doing this?
...
I know some DI frameworks support this (e.g. Ninject), but I specifically want to know if it's possible with Autofac.
I want to be able to ask an Autofac container for a concrete class, and get back an instance with all appropriate constructor dependencies injected, without ever registering that concrete class. I.e., if I never bind it ...
I would like to inject ILog into my classes, not an ILoggerFactoryAdapter, but the ILoggerFactoryAdapter needs the name of the calling class (the class that wants to log something, so i can be properly categorized) so can Autofac somehow identify the class which are requesting the ILog and automaticly create the ILog from the factory?
...
Given the following code, how do I resolve the right SomeInstance in autofac?
public class BaseClass {}
public class SubClass1 : BaseClass {}
public class SubClass2 : BaseClass {}
public interface IGenericInterface<T> where T : BaseClass {}
public class SomeInstance1<T> : IGenericInterface<T> where T : SubClass1
public class SomeIn...
I have a bunch of types registered with Autofac and some of the dependencies are rather deep. Is there a built in way to test that I can resolve all registered types? I want to fail fast at application startup, and not several minutes later part way in.
This is what I'm currently doing, and it seems to work, but I still wonder if there...
Can't get my head around the parameter passing in Autofac, the following code doesn't work:
class Config {
public Config(IDictionary<string, string> conf) {}
}
class Consumer {
public Consumer(Config config) {}
}
void Main()
{
var builder = new Autofac.Builder.ContainerBuilder();
builder.Register<Config>();
builder...
My custom error messages quit working somewhere along the way and I'm getting this error. Any ideas?
Autofac.ComponentNotRegisteredException: The requested service 'controller.error.aspx' has not been registered.
I have never done anything to register them before.
I saw several questions about the custom error messages, but I couldn'...
Autofac newbie here, but I like what I see so far. I'm trying to take advantage of request-lifetime of my resolved objects and I'm having trouble confirming that a dispose is actually happening after a request is done.
I have a disposable object that I get at the start of a page request and dispose at the end. I'm using autofac to get a...
I previously asked a question here about autofac not disposing my objects when the HTTP request ends. I now think I have a bigger problem, becuasse there is evidence that it is serving up the SAME object request-to-request. Again, I am using thier instructions here. My test is a bit more complex because I'm using the delegate syntax to c...
I've been working thru the details of implementing IoC in my web apps but in a way that leverages Microsoft.Practices.ServiceLocation. I am specifically using Autofac and the asp.net integration, but I wanted to leave myself open to other containers. Along the lines of this question, i was concerned about how to access the container in m...