小编Ant*_*iry的帖子

在Configure方法中,asp net core请求服务返回null

我正在尝试在configure方法中获取一些服务,这样我就可以更轻松地使用它们来构建数据库.

所以我在我的Configure方法中注入了IServiceProvider,但每次都这样做:var service = serviceProvider.GetService<UserService>();它返回null ...

这是我的代码:

public class Startup
    {
        public Startup(IHostingEnvironment env)
        {
            var builder = new ConfigurationBuilder()
                .SetBasePath(env.ContentRootPath)
                .AddJsonFile("appsettings.json", optional: true, reloadOnChange: true)
                .AddJsonFile($"appsettings.{env.EnvironmentName}.json", optional: true);

            builder.AddEnvironmentVariables();
            Configuration = builder.Build();
        }

        public IConfigurationRoot Configuration { get; }

        // This method gets called by the runtime. Use this method to add services to the container
        public void ConfigureServices(IServiceCollection services)
        {

            services.AddDbContext<ApplicationDbContext>(options =>
              options.UseSqlServer(this.Configuration.GetConnectionString("DbConnectionString")));

            // Add framework services.
            services.AddIdentity<IdentityUser, IdentityRole>().AddEntityFrameworkStores<IdentityDbContext>().AddDefaultTokenProviders();
            string connection = this.Configuration.GetConnectionString("DbConnectionString");
            services.AddEntityFramework(); …
Run Code Online (Sandbox Code Playgroud)

c# asp.net configuration asp.net-core

6
推荐指数
3
解决办法
7309
查看次数

服务接口中的IList,ICollection或IEnumerable?

我正在建立一个用于使用ASP.NET MVC 5中的Entity Framework访问数据库的服务。因此,我首先使用他的界面编写了一个基本服务。但是我担心一件事。

通常,我IEnumerable<T>在界面中返回一个,但通常会导致ToList()代码中的调用。

所以我想知道在这样的接口中最好返回什么。我可以返回,IList但是恐怕可能太多了,我不需要附带的所有方法IList

这是我的代码:

public interface IBaseService<T>
{
    T Add(T obj);
    T Update(T obj);
    T Remove(string id);
    T Get(string id);

    ICollection<T> Find(Expression<Func<bool, T>> func);
    ICollection<T> GetAll();
}
Run Code Online (Sandbox Code Playgroud)

c# asp.net-mvc

4
推荐指数
1
解决办法
1185
查看次数

Ionic 4 从另一个模态中打开模态:modal.create() 不是函数

我正在尝试从另一个模态对话框中打开一个模态对话框,通过在网络上搜索,我可以看到人们以前没有问题地做过它,但我似乎无法让它工作。

当我尝试从第一个模态组件创建我的第二个模态组件时,它说:

类型错误:this.modal.create 不是函数

这是我的代码(用相关部分修剪)。

组件.module.ts

@NgModule({
  declarations: [
    QuizResultComponent,
    AnswerRecapComponent
  ],
  imports: [CommonModule, FormsModule, IonicModule, FontAwesomeModule],
  exports: [
    QuizResultComponent,
    AnswerRecapComponent
  ],
  entryComponents: [
    QuizResultComponent,
    AnswerRecapComponent
  ]
})
export class ComponentsModule {}
Run Code Online (Sandbox Code Playgroud)

这是我打开第一个模态的方式: Exam.page.ts

... 
export class ExamPage implements OnInit {

    ...

    constructor(
        private router: Router,
        private modal: ModalController
    ) {}

    ...

    async openModal(){
        // Creating the result modal
        const modal = await this.modal.create({
        component: QuizResultComponent,
        componentProps: {
            type: 'exam'
        }
        });

        // Registering back to menu event after dismiss …
Run Code Online (Sandbox Code Playgroud)

typescript ionic-framework angular ionic4

4
推荐指数
1
解决办法
3962
查看次数

使用 golang 和 sqlserver 驱动程序带参数查询

我正在尝试从我的 sql server 数据库中按 ID 获取特定项目。这是我的代码:

var(
    allArticlesQry string = "SELECT * FROM Articles"
    findArticlesQry string = "SELECT * FROM Articles WHERE Id = ?1"
)

func FindArticle(w http.ResponseWriter, r *http.Request){
    vars := mux.Vars(r)
    var id = vars["id"]
    var article Article

    db := connect()
    defer db.Close()

    stmt, err := db.Prepare(findArticlesQry)    
    if err != nil{
        log.Fatal(err)
    }
    defer stmt.Close()

    err = stmt.QueryRow(id).Scan(&article.Title, &article.Description, &article.Body, &article.Id)
    if err != nil{
        log.Fatal(err)
    }

    w.Header().Set("Content-Type", "application/json; charset=UTF-8")
    w.WriteHeader(http.StatusOK)
    json.NewEncoder(w).Encode(u.HttpResp{Status: 200, Body: article})
}
Run Code Online (Sandbox Code Playgroud)

我正在使用 …

sql sql-server rest go

3
推荐指数
1
解决办法
6442
查看次数

如何用这样的html和css绘制圆圈?

到目前为止,我一直试图在这里绘制这个圆圈.

 <div class="circle">
      <svg height="360" width="380">
           <circle cx="50" cy="50" r="50"  fill="rgb(177,236,250"></circle>
           <circle cx="100" cy="120" r="90"  fill="rgb(177,236,250)" ></circle>
           <circle cx="290" cy="220" r="160"  fill="rgb(177,236,250)"></circle>
           <circle cx="80" cy="220" r="80"  fill="rgb(177,236,250)"></circle>
      </svg>
</div>
Run Code Online (Sandbox Code Playgroud)

但它看起来如此不同.

圆圈透明

html css

1
推荐指数
1
解决办法
282
查看次数

使用 XmlWriter 重写命名空间给我 XmlException

我正在尝试为 OpenClinica(一个使用 CDISC ODM XML 表示形式的临床试验平台)编写 XML 文件。我的问题是,当我尝试使用 XmlWriter 编写 XML 的第一个元素时,出现以下异常:

An exception of type 'System.Xml.XmlException' occurred in System.Xml.dll but  
was not handled in user code

Additional information: The prefix '' cannot be redefined from '' to 
'http://www.cdisc.org/ns/odm/v1.3' within the same start element tag.
Run Code Online (Sandbox Code Playgroud)

这是我想要在文件中包含的内容:

<ODM xmlns="http://www.cdisc.org/ns/odm/v1.3" 
     xmlns:OpenClinica="http://www.openclinica.org/ns/odm_ext_v130/v3.1" 
     xmlns:OpenClinicaRules="http://www.openclinica.org/ns/rules/v3.1" 
     xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
     FileOID="testD20161121140900+0000" 
     Description="test" 
     CreationDateTime="2016-11-21T14:09:00+00:00" 
     FileType="Snapshot" 
     ODMVersion="1.3" 
     xsi:schemaLocation="http://www.cdisc.org/ns/odm/v1.3 OpenClinica-ODM1-3-0-OC2-0.xsd">
Run Code Online (Sandbox Code Playgroud)

这是我的代码:

StringWriter swriter = new StringWriter();
XmlWriter writer = XmlWriter.Create(swriter);

writer.WriteStartElement("ODM");
writer.WriteAttributeString("xmlns", "http://www.cdisc.org/ns/odm/v1.3");
writer.WriteAttributeString("xmlns", "OpenClinica", null, "http://www.openclinica.org/ns/odm_ext_v130/v3.1");
writer.WriteAttributeString("xmlns","OpenClinicaRules",null, "http://www.openclinica.org/ns/rules/v3.1");
writer.WriteEndElement();

writer.Close();
return …
Run Code Online (Sandbox Code Playgroud)

c# xml

0
推荐指数
1
解决办法
946
查看次数