public void Init()
        {
            ConfigurationManager.ConnectionStrings.Add(
                new ConnectionStringSettings("DefaultConnection", "Server=localhost;Database=koshiyam;Uid=uniuser;Pwd=unipass;")
                );
            Session = NHibernateConfiguration.OpenSession();


            var builder = new ContainerBuilder();

            builder.RegisterApiControllers(Assembly.GetAssembly(typeof(Startup)));
            AutofacInfrastructureConfiguration.Configure(builder);
            AutofacDomainConfiguration.Configure(builder);
            Container = builder.Build();
        }
Example #2
0
        public void AutofacDomainConfiguration_MyService_CanBeInstantinated()
        {
            MyService resultServiceInstance;
            var       builder = new ContainerBuilder();

            AutofacDomainConfiguration.Configure(builder);
            AutofacInfrastructureConfiguration.Configure(builder);
            var container = builder.Build();

            Assert.DoesNotThrow(() => {
                //resultServiceInstance = container.Resolve<MyService> ();
                using (var scope = container.BeginLifetimeScope())
                {
                    resultServiceInstance = scope.Resolve <IMyService> () as MyService;
                    Assert.IsTrue(scope.IsRegistered <IMyService> (), "IMyService is registered");
                    Assert.IsNotNull(resultServiceInstance, "MyService is initialized");
                }
            });
        }
Example #3
0
        public static void ConfigureWebApi(HttpConfiguration config)
        {
            // Web API configuration and services

            // Web API routes
            config.MapHttpAttributeRoutes();

            config.Routes.MapHttpRoute(
                name: "Api",
                routeTemplate: "api/{controller}/{action}/{id}",
                defaults: new { id = RouteParameter.Optional, action = RouteParameter.Optional }
                );

            config.Routes.MapHttpRoute(
                name: "Default",
                routeTemplate: "",
                defaults: new { controller = "Default", action = "Get" }
                );

            var builder = new ContainerBuilder();

            builder.RegisterApiControllers(Assembly.GetExecutingAssembly());
            AutofacDomainConfiguration.Configure(builder);
            AutofacInfrastructureConfiguration.Configure(builder);
            var container = builder.Build();

            config.DependencyResolver = new AutofacWebApiDependencyResolver(container);

            //config.Formatters.Clear ();
            //config.Formatters.Add (new XmlMediaTypeFormatter ());
            //config.Formatters.Add (new JsonMediaTypeFormatter());
            //config.Formatters.Add (new FormUrlEncodedMediaTypeFormatter ());

            var settings = config.Formatters.JsonFormatter.SerializerSettings;

            settings.Formatting       = Formatting.Indented;
            settings.ContractResolver = new CamelCasePropertyNamesContractResolver();
        }