GithubHelp home page GithubHelp logo

direg's Introduction

DiReg

Результат последней сборки master ветки: CircleCI

О проекте

Репозиторий содержит маленький атрибут для .net core 2.2 приложений, позволяющий регистрировать классы в MS Dependency Injection.
Собирается в NuGet пакет.

Установка

dotnet add package Katren.DiReg

Использование

После успешной установки пакета для регистрации всех классов с атрибутом DiReg достаточно вызывать метод расширения IServiceCollection.AddDiRegClasses().

Для регистрации вашего класса в DI достаточно указать ему атрибут DiReg.
Возможны 2 варианта использования:

1. Простая регистрация, когда тип сервиса совпадает с типом имплементации такового

[DiReg(DiLifetime: lifeTime)]
public class SimpleRegClass {}

Эквивалентно вызову:

IServiceCollection.Add***(SimpleRegClass, SimpleRegClass);

2. Регистрация сервиса, когда тип сервиса не совпадает с типом имплементации такового

public interface ISomeService {}

[DiReg(typeof(ISomeService), DiLifetime: lifeTime)]
public class SomeService {}

Эквивалентно вызову:

IServiceCollection.Add***(ISomeService, SomeService);

В любом случае, неоходимо всегда указывать тип жизненного цикла регистрируемого сервиса.
Делается это с помощью enum DiLifetime.
Поддерживается 3 варианта жизненного цикла:

  • DiLifetime.Singleton - Синглтон. Эквивалентно вызову метода:

    IServiceCollection.AddSingleton(***);
  • DiLifetime.Scoped - Создаётся ровно 1 экземпляр в рамках скоупа. Например, для AspNet один экземпляр на обработку запроса. Эквивалентно вызову метода:

    IServiceCollection.AddScoped(***);
  • DiLifetime.Transient - Создавать экземпляр класса на каждый запрос. Эквивалентно вызову метода:

    IServiceCollection.AddTransient(***);

direg's People

Contributors

artemzibarev avatar perfectdigger avatar

Stargazers

Vladimir Myasnichenko avatar Constantine avatar  avatar

Watchers

James Cloos avatar Constantine avatar  avatar

Forkers

zslicker

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.