forked from bugthesystem/FireSharp
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Implement simple usage with Autofac to sample project
- Loading branch information
1 parent
f61e2f8
commit fa74598
Showing
6 changed files
with
89 additions
and
25 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
using System.Web.Mvc; | ||
using System.Web.Routing; | ||
using Autofac; | ||
using Autofac.Integration.Mvc; | ||
using FireSharp.Config; | ||
using FireSharp.Interfaces; | ||
using FireSharp.WebApp.App_Start; | ||
|
||
namespace FireSharp.WebApp | ||
{ | ||
public static class Bootstrapper | ||
{ | ||
const string BASE_PATH = "https://firesharp.firebaseio.com/"; | ||
const string FIREBASE_SECRET = "fubr9j2Kany9KU3SHCIHBLm142anWCzvlBs1D977"; | ||
public static void Start() | ||
{ | ||
AreaRegistration.RegisterAllAreas(); | ||
|
||
FilterConfig.RegisterGlobalFilters(GlobalFilters.Filters); | ||
RouteConfig.RegisterRoutes(RouteTable.Routes); | ||
|
||
var builder = new ContainerBuilder(); | ||
|
||
// Register your MVC controllers. | ||
builder.RegisterControllers(typeof(MvcApplication).Assembly); | ||
|
||
builder.Register(context => new FirebaseConfig | ||
{ | ||
BasePath = BASE_PATH, | ||
AuthSecret = FIREBASE_SECRET | ||
}).As<IFirebaseConfig>().SingleInstance(); | ||
|
||
builder.RegisterType<FirebaseClient>().As<IFirebaseClient>().SingleInstance(); | ||
|
||
|
||
var container = builder.Build(); | ||
DependencyResolver.SetResolver(new AutofacDependencyResolver(container)); | ||
|
||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,16 +1,32 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Web; | ||
using System.Web.Mvc; | ||
using FireSharp.Interfaces; | ||
|
||
namespace FireSharp.WebApp.Controllers | ||
{ | ||
public class HomeController : Controller | ||
{ | ||
private readonly IFirebaseClient _firebaseClient; | ||
|
||
public HomeController(IFirebaseClient firebaseClient) | ||
{ | ||
_firebaseClient = firebaseClient; | ||
} | ||
|
||
public ActionResult Index() | ||
{ | ||
return View(); | ||
} | ||
|
||
public ActionResult CallFirebase() | ||
{ | ||
_firebaseClient.Push("chat/", new | ||
{ | ||
name = "someone", | ||
text = "Hello from backend :" + DateTime.Now.ToString("f") | ||
}); | ||
|
||
return RedirectToAction("Index"); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,24 +1,12 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Web; | ||
using System.Web.Http; | ||
using System.Web.Mvc; | ||
using System.Web.Routing; | ||
using FireSharp.WebApp.App_Start; | ||
using System.Web; | ||
|
||
namespace FireSharp.WebApp | ||
{ | ||
// Note: For instructions on enabling IIS6 or IIS7 classic mode, | ||
// visit http://go.microsoft.com/?LinkId=9394801 | ||
public class MvcApplication : System.Web.HttpApplication | ||
public class MvcApplication : HttpApplication | ||
{ | ||
protected void Application_Start() | ||
{ | ||
AreaRegistration.RegisterAllAreas(); | ||
|
||
FilterConfig.RegisterGlobalFilters(GlobalFilters.Filters); | ||
RouteConfig.RegisterRoutes(RouteTable.Routes); | ||
Bootstrapper.Start(); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,11 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
|
||
<packages> | ||
<package id="Microsoft.AspNet.Mvc" version="4.0.20710.0" targetFramework="net45" /> | ||
<package id="Microsoft.AspNet.Mvc.FixedDisplayModes" version="1.0.0" targetFramework="net45" /> | ||
<package id="Microsoft.AspNet.Razor" version="2.0.20715.0" targetFramework="net45" /> | ||
<package id="Microsoft.AspNet.WebPages" version="2.0.20710.0" targetFramework="net45" /> | ||
<package id="Microsoft.Web.Infrastructure" version="1.0.0.0" targetFramework="net45" /> | ||
<package id="Autofac" version="3.1.0" targetFramework="net45" /> | ||
<package id="Autofac.Mvc4" version="3.1.0" targetFramework="net45" /> | ||
<package id="Microsoft.AspNet.Mvc" version="4.0.20710.0" targetFramework="net45" /> | ||
<package id="Microsoft.AspNet.Mvc.FixedDisplayModes" version="1.0.0" targetFramework="net45" /> | ||
<package id="Microsoft.AspNet.Razor" version="2.0.20715.0" targetFramework="net45" /> | ||
<package id="Microsoft.AspNet.WebPages" version="2.0.20710.0" targetFramework="net45" /> | ||
<package id="Microsoft.Web.Infrastructure" version="1.0.0.0" targetFramework="net45" /> | ||
</packages> |