Sep 18, 2018

Visual Studio Snippet - IoC service reference

Standard pattern for IOC is to register you service interface through private field and constructor.
Here is Visual Studio snippet to help with that.
It's not fully auto but helps a lot to me.

<?xml version="1.0" encoding="utf-8"?>
<CodeSnippets xmlns="http://schemas.microsoft.com/VisualStudio/2005/CodeSnippet">
    <CodeSnippet Format="1.0.0">
        <Header>
            <Title>IoCserviceReference</Title>
              <Shortcut>iocsrv</Shortcut>
        </Header>
        <Snippet>
            <Declarations>
            <Object>
                <ID>IService</ID>
                <Type>Interface</Type>
                <ToolTip>Service interface.</ToolTip>
                <Default>IService</Default>
            </Object>
            <Object>
                <ID>ServiceVar</ID>
                <Type>object</Type>
                <ToolTip>Service variable.</ToolTip>
                <Default>serviceVar</Default>
            </Object>
            </Declarations>
            <Code Language="CSharp">
                <![CDATA[
                    private readonly I$IService$ _$IService$ = null;
                    I$IService$ $IService$
                    _$IService$ = $IService$ ?? throw new ArgumentNullException(nameof($IService$));
                ]]>
            </Code>
        </Snippet>
    </CodeSnippet>
</CodeSnippets>

No comments:

Post a Comment