我创建了一个在IIS中创建网站的功能,但我遇到了一个奇怪的错误.
这是我一直在使用的网址作为参考:
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) 为了帮助提高我对IOC的理解以及如何使用它,我想创建一个所有三种IOC技术的示例:构造函数注入,Setter注入和接口注入,而不必使用第三方框架.我想我有一个构造函数注入的基本示例,但在使用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)