小编Eri*_*ter的帖子

新项IIS:\ Sites\SiteName - 索引超出了数组的范围

我创建了一个在IIS中创建网站的功能,但我遇到了一个奇怪的错误.

这是我一直在使用的网址作为参考:

http://learn.iis.net/page.aspx/433/powershell-snap-in-creating-web-sites-web-applications-virtual-directories-and-application-pools/

New-Item:索引超出了数组的范围.

在行:1 char:9 + New-Item <<<<'IIS:\ Sites\SiteName'-phyicalPath"$ sitePath"-bindings @ {protocol ="$ protocol"; bindingInformation ="$ fullBindings"} + CategoryInfo: NotSpecified:(:) [New-Item],IndexOutOfRangeException + FullyQualifiedErrorId:System.IndexOutOfRangeException,Microsoft.PowerShell.Commands.NewItemCommand

这是调用函数的代码块:

    function Create-FullSite($site, $framework, $userName, $password, $protocol, $port, $enabledProtocols)
            {
                #Write-Host "Prompting for path to "
                $sitePath = Select-Folder

                #Write-Host $sitePath

                #Write-Host "Setting up app pool for "
                $csServicePool = New-Item -Path iis:\AppPools\$site

                #Write-Host "Configuring app pool"
                Set-ItemProperty -Path IIS:\AppPools\$site -name managedRuntimeVersion -value $framework
                $csServicePool.processModel.username = $userName
                $csServicePool.processModel.password = $password
                $csServicePool.processModel.identityType = 3
                $csServicePool  | set-item …
Run Code Online (Sandbox Code Playgroud)

powershell

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

自定义IOC容器 - 需要2/3类型的帮助

背景

为了帮助提高我对IOC的理解以及如何使用它,我想创建一个所有三种IOC技术的示例:构造函数注入,Setter注入和接口注入,而不必使用第三方框架.我想我有一个构造函数注入的基本示例,但在使用setter和接口注入方面苦苦挣扎.

我的问题

您将如何从头开始处理写入界面和设置器注入?

这是我的想法,如果我走在正确的轨道上,请告诉我.

接口注入:

  1. 循环遍历使用构造函数注入实例化的已解析对象,检查以查看interfaceDependencyMap中实现的接口
  2. 定义某种interfaceDependencyMap以将接口与实现相关联.
  3. 使用interfaceDependencyMap解析实现
  4. 将适当的属性分配给使用构造函数注入初始化的对象

塞特犬注射:

  1. 循环使用构造函数注入实例化的已解析对象
  2. 定义某种setterInjectionMap
  3. 使用构造函数映射从MethodInfo解析预期参数
  4. 调用传入已解析参数对象的setter方法

这是我到目前为止构造函数注入的内容

public class Program
{
    static void Main(string[] args)
    {
        //
        //instead of doing this:
        //
        //ICreditCard creditCard = new Visa();
        //var customer = new Customer(creditCard);
        //customer.Charge();


        var resolver = new Resolver();

        //map the types in the container
        resolver.Register<Customer, Customer>();
        resolver.Register<ICreditCard, Visa>();

        //because the customer constructor has an ICreditCard parameter
        //our container will automatically instantiate it recursively
        var customer = resolver.Resolve<Customer>();

        customer.Charge();

    }
}

public …
Run Code Online (Sandbox Code Playgroud)

c# ioc-container inversion-of-control

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