小编Fai*_*est的帖子

Koin 将 viewmodel 注入 Composable

我正在尝试使用 Koin 注入我的 viewModel (它也有一些依赖项),如下所示:

未解决的参考

我不明白为什么当我进行以下导入时它找不到 getViewModel:

科因导入

我正在使用这个 Koin 版本:实现“io.insert-koin:koin-android:$koin_version”

其中 $koin_version = '3.2.0-beta-1'

有什么想法为什么我的导入在这里被忽略?

android koin android-jetpack-compose

15
推荐指数
2
解决办法
8811
查看次数

Simple Injector初始化MVC和Web API控制器

我有一个Web API控制器,它有一些资源DI'd.出于后来的需要,我添加了一个MVC控制器,现在我也需要相同的资源DI'd.这是我的原始配置:

    [assembly: WebActivator.PostApplicationStartMethod(typeof(CineplexSearch.App_Start.SimpleInjectorWebApiInitializer), "Initialize")]

namespace CineplexSearch.App_Start
{
    using System.Web.Http;
    using SimpleInjector;
    using SimpleInjector.Integration.WebApi;

    public static class SimpleInjectorWebApiInitializer
    {
        /// <summary>Initialize the container and register it as Web API Dependency Resolver.</summary>
        public static void Initialize()
        {
            var container = new Container();
            container.Options.DefaultScopedLifestyle = new WebApiRequestLifestyle();

            InitializeContainer(container);

            container.RegisterWebApiControllers(GlobalConfiguration.Configuration);

            container.Verify();

            GlobalConfiguration.Configuration.DependencyResolver =
                new SimpleInjectorWebApiDependencyResolver(container);
        }

        private static void InitializeContainer(Container container)
        {
            container.Register<ICachingManager, CachingManager>(Lifestyle.Transient);
            container.Register<IDataAccessLayer, DataAccessLayer>(Lifestyle.Transient);
        }
    }
}
Run Code Online (Sandbox Code Playgroud)

我可以在同一个地方为MVC Controller注册DI吗?我可以重复使用容器吗?

更新:我必须接近,但现在我在Web API控制器中遇到一个错误,我需要一个无参数构造函数; 我尝试添加它,但当然没有注入任何东西

public static class SimpleInjectorWebApiInitializer
{
    /// <summary>Initialize the …
Run Code Online (Sandbox Code Playgroud)

c# asp.net-mvc dependency-injection simple-injector

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

DocumentClient CreateDocumentQuery async

为什么没有CreateDocumentQuery的异步版本?

例如,此方法可以是异步的:

    using (var client = new DocumentClient(new Uri(endpointUrl), authorizationKey, _connectionPolicy))
    {
        List<Property> propertiesOfUser =
            client.CreateDocumentQuery<Property>(_collectionLink)
                .Where(p => p.OwnerId == userGuid)
                .ToList();

        return propertiesOfUser;
    }
Run Code Online (Sandbox Code Playgroud)

c# azure-cosmosdb

9
推荐指数
2
解决办法
9878
查看次数

在'〜/ components / AddPlaceModal.vue'中找不到导出'AddPlaceModal'

我刚刚开始将nuxt用于vue。我在/ components文件夹中添加了一个组件,并且试图在我的页面之一中使用它。

不幸的是,编译时我得到了这个警告:

"export 'AddPlaceModal' was not found in '~/components/AddPlaceModal.vue'
Run Code Online (Sandbox Code Playgroud)

我正在尝试通过以下方式使用它:

<script>
import {mapActions, mapGetters} from 'vuex';
import {AddPlaceModal} from '~/components/AddPlaceModal.vue'; 

export default {
    components: {
        'add-place-modal': AddPlaceModal
    },
...
Run Code Online (Sandbox Code Playgroud)

组件本身看起来像:

<script>
export default {
    data() {
        googleLocation: null;
    },
...
Run Code Online (Sandbox Code Playgroud)

任何想法为什么会这样?

javascript vue.js nuxt.js

6
推荐指数
2
解决办法
2196
查看次数

处理文件时出错:multipart: NextPart: EOF

我正在尝试构建一个小型应用程序,允许您分块上传大文件。我还将添加稍后暂停的功能。

我在循环中遇到了这个错误:Errorprocessing file: multipart: NextPart: EOF

func main() {
    router := gin.Default()

    rg := router.Group("api/v1")
    {
        rg.POST("/photo", uploadFile)
    }

    router.Use(CORSMiddleware())
    router.Run()
}

func uploadFile(c *gin.Context) {
    mr, e := c.Request.MultipartReader()
    if e != nil {
        panic("Error reading request:" + e.Error())
    }

    client, e := storage.NewClient(c, option.WithAPIKey(uploadApiKey))
    bucket := client.Bucket(uploadBucket)

    for {
        p, e := mr.NextPart()

        if e == io.EOF {
            break
        } else if e != nil {
            panic("Error processing file:" + e.Error())
        }

        w := bucket.Object(p.FileName()).NewWriter(c)

        if _, e …
Run Code Online (Sandbox Code Playgroud)

file-upload xmlhttprequest go typescript

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

实体框架不比较字节数组

我使用包含SHA512哈希的EF插入数据.然后我查找相同的数据,但没有返回结果:

var searchHash = requestToFind.GetSelfSha512Hash();
var foundRequest = _complianceContext.ScoreResults
    .Where(sr => sr.SearchHash == searchHash);
Run Code Online (Sandbox Code Playgroud)

sr.SearchHash和searchHash都是byte [].

如果我取出Where子句,我会得到1个结果.任何想法为什么会这样?

c# hash entity-framework entity-framework-6

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

无法使用protobuf包

看来我无法导入这个包:github.com/golang/protobuf/proto

当我尝试build或使用时go get我得到:

cannot load github.com/golang/protobuf/proto: module github.com/golang/protobuf@latest (v1.3.2) found, but does not contain package github.com/golang/protobuf/proto
Run Code Online (Sandbox Code Playgroud)

这是一个流行的软件包,我很惊讶它似乎不起作用。 https://godoc.org/github.com/golang/protobuf/proto#Marshal

有人遇到过这种情况吗?

更新

我只是想导入这个:

import (
    "bytes"
    "context"
    "encoding/json"
    "errors"
    "fmt"
    "github.com/golang/protobuf/proto"
)
Run Code Online (Sandbox Code Playgroud)

GoLang 不解析上述路径中的 proto...

我尝试像这样安装:

$ go get github.com/golang/protobuf/proto
go: finding github.com/golang/protobuf/proto latest
go get github.com/golang/protobuf/proto: module github.com/golang/protobuf@upgrade (v1.3.2) found, but does not contain package github.com/golang/protobuf/proto
Run Code Online (Sandbox Code Playgroud)

Update2,不确定该文件有何帮助,但它是:

package main

import (
    "bytes"
    "context"
    "encoding/json"
    "errors"
    "fmt"
    "github.com/golang/protobuf/proto"
    "go_poc/plugins/com_styx_proto"
    "io/ioutil"
    "net/http"
    "time"
)

func init() …
Run Code Online (Sandbox Code Playgroud)

go protocol-buffers grpc

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

遍历通道时关闭通道的最佳时间

我正在玩Golang,我创建了这个小应用程序,使用goroutines进行了多个并发的api调用。

当应用程序运行时,调用完成后,该应用程序将卡住,这是有道理的,因为由于通道未关闭,无法退出范围c循环。

我不确定以这种方式在哪里可以更好地关闭渠道。

package main

import "fmt"
import "net/http"

func main() {
    links := []string{
        "https://github.com/fabpot",
        "https://github.com/andrew",
        "https://github.com/taylorotwell",
        "https://github.com/egoist",
        "https://github.com/HugoGiraudel",
    }

    checkUrls(links)
}

func checkUrls(urls []string) {
    c := make(chan string)

    for _, link := range urls {
        go checkUrl(link, c)
    }

    for msg := range c {
        fmt.Println(msg)
    }

    close(c) //this won't get hit
}

func checkUrl(url string, c chan string) {
    _, err := http.Get(url)

    if err != nil {
        c <- "We could not reach:" …
Run Code Online (Sandbox Code Playgroud)

go

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

Gin上传文件时不断返回204

我收到带有 OPTIONS 方法的 204,但似乎没有达到终点 在此输入图像描述

只需构建一个简单的文件上传端点,如下所示:

package main

import  (
    "cloud.google.com/go/storage"
    "github.com/gin-gonic/gin"
    "github.com/gin-contrib/cors"
    "google.golang.org/api/option"
    "io"
    "log"
)

 const uploadBucket = "some-cool-bucket-name"
 const uploadApiKey = "some-advanced-key"

func main() {
    router := gin.Default()

    rg := router.Group("api/v1/photo")
    {
        rg.PATCH("/", uploadFile)
    }

    router.Use(cors.Default())

    router.Run()
}

func uploadFile(c *gin.Context) {
    mr, e := c.Request.MultipartReader()
    if e != nil {
        panic("Error reading request")
    }

    client, e := storage.NewClient(c, option.WithAPIKey(uploadApiKey))
    bucket := client.Bucket(uploadBucket)

    for {
        p, e := mr.NextPart()

        if e == io.EOF {
            break
        } else if …
Run Code Online (Sandbox Code Playgroud)

go go-gin

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