2016-11-21 65 views
0

我正在尝试在我的Asp.Net Core项目上安装和配置Autofac。我在名为CustomerOrder.Web的Asp.Net Core项目中引用了一个名为CustomerOrder.Data的项目。我能够看到成功引用的项目,并且可以使用using关键字访问命名空间。虽然名称空间中的某个类名称变为红色。例如。使用CustomerOrder.Data.Infrastructure的命名空间 ;读取名称空间中的数据。因此它无法确定我在web项目中引用的接口和类。下面是代码在CustomerOrder.Data项目在.net核心项目中引用项目后无法读取程序集

Project.Json文件

{ 
    "version": "1.0.0-*", 

    "dependencies": { 
    "CustomerOrder.Model": "1.0.0-*", 
    "Microsoft.EntityFrameworkCore": "1.1.0", 
    "Microsoft.EntityFrameworkCore.Relational": "1.0.1", 
    "Microsoft.Extensions.Caching.Abstractions": "1.1.0", 
    "NETStandard.Library": "1.6.1" 
    }, 

    "frameworks": { 
    "netstandard1.6": { 
     "imports": "dnxcore50" 

    } 
    } 
} 

对于CustomerOrder.Data项目

namespace CustomerOrder.Data.Infrastructure 
{ 
    public class DbFactory : Disposable, IDbFactory 
    { 
     CustomerOrderEntities _dbContext; 
     private DbContextOptions<CustomerOrderEntities> _options; 

     public CustomerOrderEntities Init() 
     { 
      _options = new DbContextOptions<CustomerOrderEntities>(); 
      return _dbContext ?? (_dbContext = new CustomerOrderEntities(_options)); 
     } 

     protected override void DisposeCore() 
     { 
      _dbContext?.Dispose(); 
     } 
    } 
} 

Startup.cs如DBFactory类文件中CustomerOrder.Web项目

01在CustomerOrder.Web项目

{ 
    "dependencies": { 
    "Microsoft.NETCore.App": { 
     "version": "1.1.0", 
     "type": "platform" 
    }, 
    "Microsoft.AspNetCore.AngularServices": "1.0.0-beta-000019", 
    "Microsoft.AspNetCore.Diagnostics": "1.0.0", 
    "Microsoft.AspNetCore.Mvc": "1.0.1", 
    "Microsoft.AspNetCore.Razor.Tools": { 
     "version": "1.1.0-preview4-final", 
     "type": "build" 
    }, 
    "Microsoft.AspNetCore.Server.IISIntegration": "1.0.0", 
    "Microsoft.AspNetCore.Server.Kestrel": "1.0.1", 
    "Microsoft.AspNetCore.StaticFiles": "1.0.0", 
    "Microsoft.Extensions.Configuration.EnvironmentVariables": "1.0.0", 
    "Microsoft.Extensions.Configuration.Json": "1.0.0", 
    "Microsoft.Extensions.Configuration.CommandLine": "1.1.0", 
    "Microsoft.Extensions.Logging": "1.1.0", 
    "Microsoft.Extensions.Logging.Console": "1.0.0", 
    "Microsoft.Extensions.Logging.Debug": "1.0.0", 
    "Microsoft.Extensions.Options.ConfigurationExtensions": "1.0.0", 
    "Autofac.Extensions.DependencyInjection": "4.0.0", 
    "Microsoft.EntityFrameworkCore.SqlServer": "1.1.0", 
    "Microsoft.EntityFrameworkCore": "1.1.0", 
    "Microsoft.EntityFrameworkCore.Relational": "1.1.0", 
    "CustomerOrder.Data": "1.0.0-*", 
    "CustomerOrder.Model": "1.0.0-*", 
    "CustomerOrder.Service": "1.0.0-*" 
    }, 

    "tools": { 
    "Microsoft.AspNetCore.Razor.Tools": "1.1.0-preview4-final", 
    "Microsoft.AspNetCore.Server.IISIntegration.Tools": "1.1.0-preview4-final", 
    "Microsoft.DotNet.Watcher.Tools": "1.1.0-preview4-final" 
    }, 

    "frameworks": { 
    "netcoreapp1.6": { 
     "imports": [ 
     "dnxcore50", 
     "portable-net45+win8" 
     ] 
    } 
    }, 

    "buildOptions": { 
    "emitEntryPoint": true, 
    "preserveCompilationContext": true 
    }, 

    "runtimeOptions": { 
    "configProperties": { 
     "System.GC.Server": true 
    } 
    }, 

    "publishOptions": { 
    "include": [ 
     "appsettings.json", 
     "ClientApp/dist", 
     "node_modules", 
     "Views", 
     "web.config", 
     "wwwroot" 
    ] 
    }, 

    "scripts": { 
    "prepublish": [ 
     "npm install", 
     "node node_modules/webpack/bin/webpack.js --config webpack.config.vendor.js --env.prod", 
     "node node_modules/webpack/bin/webpack.js --env.prod" 
    ], 
    "postpublish": [ "dotnet publish-iis --publish-folder %publish:OutputPath% --framework %publish:FullTargetFramework%" ] 
    }, 

    "tooling": { 
    "defaultNamespace": "CustomerOrder.Web" 
    } 
} 

出于某种原因,该项目无法理解的UnitOfWork,IUnitOfWork,DbFactory,IDbFactory

Project.Json文件等

  builder.RegisterType<UnitOfWork>().As<IUnitOfWork>(); 
      builder.RegisterType<DbFactory>().As<IDbFactory>(); 
      builder.RegisterType<CustomerRepository>().As<ICustomerRepository>(); 
      builder.RegisterType<ProductRepository>().As<ICustomerRepository>(); 
      builder.RegisterType<OrderRepository>().As<IOrderRepository>(); 

似乎有一些问题与核心版本。有没有人面对过这个?

回答

0

我找到了解决这个问题的办法。 Resharper是罪魁祸首。我禁用了resharper,现在一切正常。

相关问题