简体   繁体   中英

Getting error in Asp.net core when implementing TodoList service

I'm following on some tutorial which creates TodoList and uses multiple layer structure to handle different business logic. When I copy code from the book it shows me an error when I fire dotnet run command in windows cmd. The error I get is displayed bellow so I can specify where lies the problem but don't know how to fix this. What can I do to make this work ? I'm using dotnet 3.0.100 version.

Services\\FakeTodoItemService.cs(21,17): error CS0117: 'FakeTodoItemService' does not contain a definition for 'Title' [C:\\dotnetproject\\AspNetCoreTodo\\AspNetCor eTodo\\AspNetCoreTodo.csproj]Services\\FakeTodoItemService.cs(22,17): error CS0117: 'FakeTodoItemService' doesn not contain a definition for 'DueAt' [C:\\dotnetproject\\AspNetCoreTodo\\AspNetCor eTodo\\AspNetCoreTodo.csproj]

And here is a code which I think may be responsible for this error. Basically I have a service that implements interface which uses a model.

FakeTodoItemService.cs

using System; 
using System.Collections.Generic; 
using System.Linq;
using System.Threading.Tasks;
using AspNetCoreTodo.Data;
using AspNetCoreTodo.Models;

namespace AspNetCoreTodo.Services
 {              
    public class FakeTodoItemService : ITodoItemService             
    {                               
        public Task<TodoItem[]> GetIncompleteItemsAsync()
        {
            var item1 = new TodoItem
            {
                Title = "Learn ASP.NET Core",
                DueAt = DateTimeOffset.Now.AddDays(1)
            };
            var item2 = new FakeTodoItemService
            {
                Title = "Build awesome apps",
                DueAt = DateTimeOffset.Now.AddDays(2)
            };

             return Task.FromResult(new[] {item1, item2});
        }
    } 
 }

TodoItem.cs

using System;
using System.ComponentModel.DataAnnotations;

namespace AspNetCoreTodo.Models
{
    public class TodoItem
    {
        public Guid Id {get; set;}

        public bool IsDone {get; set;}

        [Required]
        public string Title {get; set;}

        public DateTimeOffset? DueAt {get; set;}
    }
}

ITodoItemService.cs

using System;
using System.Collections.Generic; 
using System.Threading.Tasks;
using AspNetCoreTodo.Models;


namespace AspNetCoreTodo.Services 
{
    public interface ITodoItemService 
    {
        Task<TodoItem[]> GetIncompleteItemsAsync();
    } 
}

In FakeTodoItemService.GetIncompleteItemsAsync you have this line var item2 = new FakeTodoItemService . FakeTodoItemService should be TodoItem .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM