Skip to content
This repository has been archived by the owner on Apr 26, 2020. It is now read-only.

Autofac 4.0 #25

Open
janus007 opened this issue Aug 5, 2015 · 13 comments
Open

Autofac 4.0 #25

janus007 opened this issue Aug 5, 2015 · 13 comments

Comments

@janus007
Copy link

janus007 commented Aug 5, 2015

Hello

I was trying to get AutofacNancyBootstrapper to work with Autofac 4.0 because I wanted to use .NET 4.5.2 in Visual Studio 2015, but with no luck.

It seems that AutofacNancyBootstrapper utilizes ILifetimeScope and that appears not to work with Autofac 4.0

So my question... when will I be able to use Autofac 4.0?

Thank you for a great product.

@khellang
Copy link
Member

khellang commented Aug 6, 2015

Uuuh... ILifetimeScope is kinda the core interface in Autofac. It would be weird if they dropped it in 4.0. I even think I've seen the interface provide scoping to the ASP.NET 5 dependency injection stuff.

I'll check and come back to you, but we probably wouldn't update anything to require 4.0 until it's out of beta, at least. Maybe @tillig or @alexmg could provide some insight here?

BTW, why can't you use .NET 4.5.2 with an older version? 😜

@janus007
Copy link
Author

janus007 commented Aug 6, 2015

Hi khellang
That was quick reply :) They didn't drop it, I can see that my previous post could indicate that.

The case is that I'm trying to use ASP.NET 4.5.2 and AutofacRegistration.Populate or builder.Populate, either way this extension method exists in Autofac 4.* and as soon I reference that, the AutofacNancyBootstrapper complains about the Autofac version.

Normally I would just do an assembly-binding, but that is not possible in vNext, it is being said that assembly-version is carried out by Roslyn, but apparently this is not working. Don't now why, but I guess it has something to do with the target framework that Nancy is built in, at the moment 4.0.

In my desperation for a temporary solution, I cloned Nancy.Bootstrappers.Autofac and changed Autofac to version Autofac 4.0.0-alpha2 , but I gave up :)

Install-Package : Failed to add reference to 'System.Runtime'. Please make sure that it is in the Global Assembly Cache.
At line:1 char:16

  • Install-Package <<<< Autofac -Version 4.0.0-alpha2 -Pre
    • CategoryInfo : NotSpecified: (:) [Install-Package], Exception
    • FullyQualifiedErrorId : NuGetCmdletUnhandledException,NuGet.PackageManagement.PowerShellCmdlets.InstallPackageCommand

@khellang
Copy link
Member

khellang commented Aug 6, 2015

Right, so this has nothing to do with .NET 4.5.2, but rather that you're trying to use this in a DNX project? We don't support DNX yet. We have a branch going in the main repo to get Nancy running on it. In fact I think it runs on DNX451, but not on DNXCORE50, right now. Before we ship that, we'll make sure to have a version of the different bootstrappers that works with it.

@janus007
Copy link
Author

janus007 commented Aug 6, 2015

Amazing... I will look forward to compatibility with 451.

@radams0x
Copy link

radams0x commented Sep 2, 2015

Hello,
I'm having the same issue trying to use dnx451. I'll keep an eye out for your updated bootstrapper. Thanks!

@khellang
Copy link
Member

khellang commented Sep 2, 2015

If you really want to use Nancy with Autofac on DNX451, you can simply copy the bootstrapper over as source, temporarily.
I've created a sample repo over at https://github.com/khellang/Nancy.Autofac.Dnx where I did this.
The sample runs nicely using Nancy on DNX451 with Autofac in harmony with IServiceCollection and co 😁

I've even demonstrated it by using DNX's logging infrastructure inside a Nancy module. Here's the output:

$ dnx . web
> info    : [Microsoft.Net.Http.Server.WebListener] Start
> info    : [Microsoft.Net.Http.Server.WebListener] Listening on prefix: http://localhost:5000/
> Started
> info    : [WebApplication1.HelloWorldModule] Hello World!
> info    : [Microsoft.Net.Http.Server.WebListener] Dispose
> info    : [Microsoft.Net.Http.Server.WebListener] Stop listening on prefix: http://localhost:5000/

@radams0x
Copy link

radams0x commented Sep 2, 2015

Wow, thank you so much for this! I was actually just in the process of doing that, but but this helped me as I couldn't get it to compile and hadn't noticed the need for the ComponentContextExtensions.cs.
I'll give it a whirl and post the results.
Thanks!!

@khellang
Copy link
Member

khellang commented Sep 2, 2015

No problem 👍 BTW, you don't need Autofac 4.0 to run on DNX. You only need it if you want to use Autofac.Framework.DependencyInjection, which contains the Populate method to populate the ContainerBuilder using an IServiceCollection. If you don't need services from DNX, you can get by with simply using the Nancy.Bootstrappers.Autofac package.

@radams0x
Copy link

radams0x commented Sep 2, 2015

HI khellang,

I got it to work as you describe, use the code you posted. at https://github.com/khellang/Nancy.Autofac.Dnx

I am using Autofac.Framework.DependencyInjection, which contains the Populate method to populate the ContainerBuilder using an IServiceCollection.

Thank you so much for everything!!

@janus007
Copy link
Author

janus007 commented Sep 2, 2015

Haven't tested it, but I believe radams0x is right on.

khellang, I thank you very much for this :)

@khellang
Copy link
Member

khellang commented Sep 2, 2015

Glad to hear 👍 I'll leave this issue open until we get a permanent solution 😄

@khellang
Copy link
Member

@norgie What are you talking about? You shouldn't have to implement anything. All those methods you mention are implemented by the AutofacNancyBootstrapper.

@khellang
Copy link
Member

Heh. What version of R# are you using? Some EAP?

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants