Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/271.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 将Autofac与Microsoft Azure移动服务集成_C#_Azure Mobile Services - Fatal编程技术网

C# 将Autofac与Microsoft Azure移动服务集成

C# 将Autofac与Microsoft Azure移动服务集成,c#,azure-mobile-services,C#,Azure Mobile Services,我已经创建了一个移动表格控制器: [MobileAppController] [Authorize] public class EventOrganiserMembershipDtoController : TableController<EventOrganiserMembershipDto> { private readonly IModelContext _modelContext; public EventOrganiserMembershipDtoCont

我已经创建了一个移动表格控制器:

[MobileAppController]
[Authorize]
public class EventOrganiserMembershipDtoController : TableController<EventOrganiserMembershipDto>
{
    private readonly IModelContext _modelContext;

    public EventOrganiserMembershipDtoController(IModelContext modelContext)
    {
        _modelContext = modelContext;
    }

    protected override void Initialize(HttpControllerContext controllerContext)
    {
        base.Initialize(controllerContext);
        DomainManager = new EventOrganiserMembershipDomainManager((DbContext)_modelContext, controllerContext.Request);
    }
}
但是它不接受依赖注入,尽管我已经在我的项目中设置了它

根据我所做的所有搜索,为了完成这个任务(这应该非常简单),我需要行ServiceConfig.Initializenew ConfigBuilderoptions。但是我不知道这个神秘的ServiceConfig类应该住在哪里。它过时了吗?有没有更新的方法可以做到这一点?

您不需要ServiceConfig调用:我认为它是传统移动服务器基础结构的一部分。您只需要将一个容器传递到scaffolding中:向样板代码添加一个IContainer参数

    public static void ConfigureMobileApp(IAppBuilder app)
    {
        HttpConfiguration config = new HttpConfiguration();

        new MobileAppConfiguration()
            .UseDefaultConfiguration()
            .ApplyTo(config);

        // Use Entity Framework Code First to create database tables based on your DbContext
        Database.SetInitializer(new MobileServiceInitializer());

        MobileAppSettingsDictionary settings = config.GetMobileAppSettingsProvider().GetMobileAppSettings();

        if (string.IsNullOrEmpty(settings.HostName))
        {
            app.UseAppServiceAuthentication(new AppServiceAuthenticationOptions
            {
                // This middleware is intended to be used locally for debugging. By default, HostName will
                // only have a value when running in an App Service application.
                SigningKey = ConfigurationManager.AppSettings["SigningKey"],
                ValidAudiences = new[] { ConfigurationManager.AppSettings["ValidAudience"] },
                ValidIssuers = new[] { ConfigurationManager.AppSettings["ValidIssuer"] },
                TokenHandler = config.GetAppServiceTokenHandler()
            });
        }

        app.UseWebApi(config);
    }
替换

HttpConfiguration config = new HttpConfiguration();


很高兴听到你已经解决了这个问题。你可以将你的回答标记为一个可接受的答案,这可以帮助其他可能遇到类似问题的社区成员。再过12个小时,我可以这样做。这就是堆栈溢出的规则。
var config = new HttpConfiguration
{
    DependencyResolver = new AutofacWebApiDependencyResolver(container)
};