Reputation: 996
I created WebApplication in local machine. It works good. But when I deploy this project to IIS i have a problem.
I understand that doing bad, but in ControllerInstaller
I write this:
container.Register(
Classes
.FromAssembly(Assembly
.LoadFrom(@"D:\Shevtsov\HarbaHabr\Habra.Web\bin\Habra.Web.dll"))
.BasedOn<IController>()
.LifestyleTransient());
It is clear that this path on the server it will not work...
Please tell me, how path I must to write here?
P.S. ControllerInstaller
in assembly Habra.ServiceLocation
.
Upvotes: 0
Views: 1188
Reputation: 41767
If you're using MVC 4 (or above), I recommend using the PreApplicationStartMethodAttribute, then simply create a class as below in your Hara.Web
assembly:
[assembly: PreApplicationStartMethod(typeof(Registration), "Register")]
public class Registration
{
public static void Register()
{
var container = ...;
container.Register(
Classes
.FromAssembly(Assembly.GetExecutingAssembly())
.BasedOn<IController>()
.LifestyleTransient());
}
}
Phill Hacck has a very good blog post about using this attribute here.
Upvotes: 0
Reputation: 1038930
You could use the MapPath method which returns the absolute path to a file on the server given a relative path starting from the root of the web application denoted by ~/
:
container
.Register(
Classes
.FromAssembly(
Assembly
.LoadFrom(HostingEnvironment.MapPath("~/bin/Habra.Web.dll"))
)
.BasedOn<IController>()
.LifestyleTransient()
);
Upvotes: 2