grpcdotnetgo

package module
v0.1.8 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jun 29, 2021 License: Apache-2.0 Imports: 5 Imported by: 0

README

gRPC-dot-net-go

Contracts

It all starts with a proto file. In our case we want to have a custom server implementation that understands that the real downstream hanlder is in our DI. Fortunately we can use a protoc plugin to generate the GO code for that.

cd example
go get -u github.com/fluffy-bunny/protoc-gen-go-di/cmd/protoc-gen-go-di
protoc --go_out=. --go_opt=paths=source_relative --go-grpc_out=. --go-grpc_opt=paths=source_relative --go-di_out=. --go-di_opt=paths=source_relative internal\grpcContracts\helloworld\helloworld.proto

This will generate all the go files from our helloworld.proto

Make it looke like dotnet core

In dotnet core when a request comes in the DI has a concept of a scope. Here we do the same thing by creating that scoped container in a middleware

    requestContainer, _ := grpcdotnetgo.GetContainer().SubContainer()
		defer requestContainer.Delete()

		ctx = setRequestContainer(ctx, requestContainer)

		contextaccessor := contextaccessor.GetInternalGetContextAccessorFromContainer(requestContainer)
		contextaccessor.SetContext(ctx)

The middleware gets a SubContainer from the root container. When we use this new requestContainer to fetch objects from it, it will honor scoped services. The main root container will NOT give you an object that has been registered as scoped for good reason as the root container is global and is there for singletons.

Documentation

Index

Constants

View Source
const (
	SupportPackageIsVersion7 = true
)

Variables

This section is empty.

Functions

func GetContainer

func GetContainer() di.Container

Types

type DotNetGoBuilder

type DotNetGoBuilder struct {
	Builder *di.Builder
}

func NewDotNetGoBuilder

func NewDotNetGoBuilder() (*DotNetGoBuilder, error)

func (*DotNetGoBuilder) Build

func (b *DotNetGoBuilder) Build()

Directories

Path Synopsis
example module
middleware
services

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL